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
4

1 に答える 1

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ループの開始前に必ずクリアしてください。

于 2013-09-26T07:09:30.017 に答える