Adding offset to base from register in MIPS

痴心易碎 提交于 2019-12-12 03:46:51

问题


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 :)



来源:https://stackoverflow.com/questions/14545896/adding-offset-to-base-from-register-in-mips

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!