Begin your loop by putting the address of r
into register $a0
. Then, 0($a0)
represents r[i]
, 4($a0)
represents r[i+1]
, and 8($a0)
represents r[i+2]
. Increment $a0
by 4 each loop. Similarly for q
which we will put in $a1
.
You don't need i
/$t1
, nor $t2
and $t3
.
Roughly something like this (it's been a few years, and I don't have an assembler handy):
la $a0,r
la $a1,q
getQuot:
lw $t8,0($a0) # $t8 = r[i]
lw $t9,4($a0) # $t8 = r[i+1]
div $t8,$t9
mflo $t4
sw $t4,4($a1) # store quotient in q[i+1]
mfhi $t4
sw $t4,8($a0) # store remainder in r[i+2]
addi $a0,$a0,4 # next r
addi $a1,$a1,4 # next q
Note that your code did not include the loop condition, which I also omitted because my recollection is so rusty. :-)