Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个寄存器($t2),它有一个随机生成的数字,然后乘以 4。我的问题是,在使用 lw 指令时是否可以使用 $t2 中的值作为偏移量?
在 MIPS 中,您可以使用寄存器、偏移量或两者相加;但不是两个寄存器组成一个有效地址。
所以,如果你想将单个寄存器指向的单词加载到,比如说$t0,你会这样做:
$t0
lw $t0, ($t2)
但是,如果您想将有效地址指向的字加载$t1 + $t2到$t0其中,则首先需要执行加法,然后从内存中加载该字,例如:
$t1 + $t2
addu $t1, $t1, $t2 lw $t0, ($t1)
考虑到执行加法会丢失$t1先前的值,因此您应该使用一些免费寄存器作为加法的目标。
$t1