StingRay21
StingRay21

Reputation: 362

MIPS - Error when printing data into array

So im attempting to put numbers 1-200 in an array. The array is at the bottom of the code. I keep getting errors when i try to print this, can anyone spot the error with me putting in the numbers? The numbers in the array are supposed to go from 1-200, so $t3 increments each time. Any advice would be greatly appreciated.

main:	
	.text
		lw $t0, numbers_size	# loads the size of the array into the loop
		la $t1, numbers			# $t1 gets the number array
		li $t2, 0				# loop control variable
		li $t3, 1				# value stored inside numbers
		
		
		li 		$v0, 4
		la 		$a0, test_2 # print before loop 
		syscall
		
number_for:
		bge 	$t2, $t0, end_for
		sw		$t3, ($t1)
		
		add $t1, $t1, 4
		add $t2, $t2, 1
		add $t3, $t3, 1		

		j number_for
end_for:
		lw $t0, numbers_size	# loads the size of the array into the loop
		la $t1, numbers			# $t1 gets the number array
		li $t2, 0				# loop control variable
		
		j print_numbers


.data
test: .asciiz "Printing numbers:"
test_2: .asciiz "Before loop:"


numbers:
	.word 0:200
numbers_size:
	.word 200

Upvotes: 0

Views: 63

Answers (1)

SkyMaster
SkyMaster

Reputation: 1323

This may help you:

.text
main:   
    lw $t0, numbers_size    # loads the size of the array into the loop
    la $t1, numbers     # $t1 gets the number array
    li $t2, 0           # loop control variable
    li $t3, 1           # value stored inside numbers

    li $v0, 4
    la $a0, test_2  # print before loop 
    syscall
    j number_for
    li $v0, 10
    syscall


number_for:
    bge $t2, $t0 end_for
    sw  $t3, ($t1)

    addi $t1, $t1, 4
    addi $t2, $t2, 1
    addi $t3, $t3, 1        

    b number_for

end_for:
    lw $t0, numbers_size    # loads the size of the array into the loop
    li $t1, 0           
    li $t2, 0           # loop control variable

buc:
    bge $t2, $t0 end
    lw $a0, numbers($t1) # Printing integer from array
    li $v0,1
    syscall

    la $a0, space   #load a space:  " "
    li $v0, 4       #print string               
    syscall

    addi $t1, $t1, 4
    addi $t2, $t2, 1
    b buc       

end:
    jr $ra

.data
test: .asciiz "Printing numbers:"
test_2: .asciiz "Before loop:\n"
space: .asciiz " "
numbers_size: 
    .word 200
numbers:
    .word 0:200

Upvotes: 1

Related Questions