0

Could someone help walk me through what some lines in this MIPs code are doing?

The C code is B[8] = A[i - j] with i = $s3, j = $s4, &A[] = $s6, and &B[] = $s7

The MIPs code is as follows...

sub $t0, $s3, $s4  # i - j
sll $t0, $t0, 2 #Gets the offset of 8 for B[]
add $t0, $s6, $t0 #Goes to the offset in B[] ?
lw $t1, 0($t0) #????
sw $t1, 32($s7) #????

I get a bit lost once it gets to the last 3 lines.

Why is it 0($t0) and 32($s7)? Or just why 0 and 32?

1
  • What is MIPs? Is that the 28 bit version of MIPS? Commented Sep 26, 2015 at 20:33

1 Answer 1

1
sll $t0, $t0, 2   // This multiplies (i-j) * 4, not 8. Because the indexes are 4-byte ints
add $t0, $s6, $t0 // $t0 = A + (i-j)*4. So $t0 = &A[i-j]
lw $t1, 0($t0)     // $t1 = A[i-j]
sw $t1, 32($s7)   // B[32/4] = $t1

32($s7) means $s7 + 32. The reason you add 32 because you are accessing the 8th element of an integer array, which is located in the memory address B + 8*sizeof(int) = B + 32

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.