f,g,h,i,j == $s0-$s4. Base address of arrays A and B are $s6 and $s7
sll $t0, $s0, 2
add $t0, $s6, $t0
sll $t1, $s1, 2
add $t1, $s7, $t1
lw $s0, 0($t0)
as far as i understand, the first line takes the value of f*4 and stores it in $t0. ive been told that we have the first line because the array is holding 4-byte values. Please explain the rest. I know the program is accessing the array somewhere but i dont understand the syntax, it just looks like the base case of array A is being added to the f*4. thanks.
sll
is shift-left-logical -- sosll $t0, $s0, 2
takes the value in$s0
(f), and shifts it left by 2 bit places, sticking the result is$t0
. That's the same as multiplying by 4, but much faster.add
is addition -- soadd $t0, $s6, $t0
takes the value in$s6
(the base address of A), and adds the$t0
value just computed above, sticking the result in$t0
(replacing the old value). This gives you the address of A[f]lw
is load word -- solw $s0, 0($t0)
loads the 4-byte value at a 0 byte offset from$t0
and sticks it in$s0
. Given the previous two instructions, this is the value of A[f]The other two instructions are computing the address of B[g] in
$t1