问题
B[8] = A[i–j];
how do you use the arrays while trying to convert into MIPS the above C expression? i thought something like :
lw $t0, 16 ($s7)
sub $t1, $s3, $s4
lw $t2, $t1 ($s6)
considering that
$s6 holds A
$s7 --- B
$s3 ---- i
and $s4 -- j
but am not sure about how to do the calculationg to actually get on A [i-j]
any suggestion?
回答1:
Well, first off, 16($s7)
is wrong. Assuming that B and A are arrays of 32-bit integers, the offset is 8 * 4 = 32
.
Next, simply add $t1
and $s6
and load from there.
lw $t0 32($s7)
sub $t1 $s3 $s4
add $t1 $s6 $t1
lw $t2 0($t1)
来源:https://stackoverflow.com/questions/21227087/array-on-mips-from-c-to-mips