2013-09-26 37 views
0

我有问题在一个循环中总结一个数组的内容。总结一个数组的内容

loop3:  
    beq $t5, $t1, loop4  #if $t5 is equal to $t1, then goto exit 

    lw $t6, 0($s0)  #load contents of $s0 to $t6 
    add $t6, $t6, $t6  #sums the contents 

    addi $s0, $s0, 4  #increments pointer of pArry 
    add $t5, $t5, 1  #increments counter of loop3 
    j loop3 

回答

1

你不是因为你在每次迭代的开始与当前数组元素覆盖$t6所有元素求和:lw $t6, 0($s0) #load contents of $s0 to $t6

负载电流元到一些其他的(免费),而不是注册:

lw $t7, 0($s0)  #load contents of $s0 to $t7 
add $t6, $t6, $t7 #sums the contents 

确保循环开始前清除$t6

+0

谢谢你的提示。我确实感觉错了。 – Kevin