Adding offset to base from register in MIPS

2019-08-22 01:19发布

问题:

If I have a number in t3, can I use lw $s3, $t3($t0) to get the value stored at the memory referenced by base+offset where the base is in t0 and the offset is in t3 into s3?

回答1:

I believe that the solution plaknas gives is only half-correct, as you have to take the word size into account when "creating" the offset in MIPS.

Here is the correct answer, assuming a word size of 4 bytes:

sll $t3, $t3, 2
add $t0, $t0, $t3
lw $s3, 0($t0)


回答2:

Apparently it cannot be done. The better way to do it is something like:

add $t4, $t0, $t3
lw $s3, 0($t4)

Thank you :)