MIPS Assembly to C
So I'm trying to translate this MIPS assembly code into C. I'm confused on
a certain part of what's going on. Here is the MIPS assembly code: Assume
we have variables f, g, h, i, j stored in $s0, $s1, $s2, $s3 and $s4,
respectively. Assume the base addresses of arrays A and B are at $s6 and
$s7 respectively and they contain 4 byte words. I have inserted comments
to show I understand most of this.
sll $t0, $s0, 2 # $t0 = f * 4
add $t0, $s6, $t0 # $t0 = &A[f]
sll $t1, $s1, 2 # $t1 = g * 4
add $t1, $s7, $t1 # $t1 = &B[g]
lw $s0, 0($t0) # f = A[f]
addi $t2, $t0, 4 <-- Here's where I am confused. Since $t0 contains the
address of A[f], what does adding 4 do to that?
lw $t0, 0($t2)
add $t0, $t0, $s0
sw $t0, 0($t1)
No comments:
Post a Comment