MIPS - 将数据打印到数组时出错

时间:2014-11-10 03:53:13

标签: arrays mips

所以我试图将数字1-200放在一个数组中。该数组位于代码的底部。当我尝试打印时,我一直都会遇到错误,有人可以通过输入数字来发现错误吗?数组中的数字应该从1-200开始,所以$ t3每次递增。任何建议都将不胜感激。

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

1 个答案:

答案 0 :(得分:1)

这可能会对您有所帮助:

.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