在 MIP 中使用数组

Using arrays in MIPs

有人可以帮我了解一下这个 MIP 代码中的某些行在做什么吗?

C 代码是 B[8] = A[i - j] i = $s3,j = $s4,&A[] = $s6,&B[] = $s7

MIPs代码如下...

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) #????

当它到达最后 3 行时,我有点不知所措。

为什么是 0($t0) 和 32($s7)?或者为什么是 0 和 32?

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) 表示$s7 + 32。之所以加32是因为你访问的是整数数组的第8个元素,它位于内存地址B + 8*sizeof(int) = B + 32