MIPS sw和lw问题
我在 MIPS 中使用 sw 和 lw 的示例中看到指令如下所示。
lw $6, 0($4)
我的第一个问题是,0() 是做什么的?如果是 lw $6, 4($4) 呢?
我正在尝试在 MARS mips 程序中进行测试,但每当我执行该程序时,lw 和 sw 似乎不会用任何值更新寄存器。例如,如果我有这段代码,
ori $t1, $t1, 8
lw $t2, 0($t1)
我希望 $t2 更新为某个值,但事实并非如此。我的第二个问题是,是否有人可以解释为什么 $t2 仍然保留 0x00000000 而不是 lw 指令执行后的值。
I have seen in examples of sw and lw being used in MIPS the instruction looks like this.
lw $6, 0($4)
My first question is, what does the 0() do? What if it was lw $6, 4($4)?
I am trying to test in the MARS mips program but whenever I execute the program the lw and sw seem to not update the registers with any values. for example if I have this code
ori $t1, $t1, 8
lw $t2, 0($t1)
I would expect $t2 to be updated to some value but this is not the case. My second question is if someone could anyone explain why $t2 still holds 0x00000000 and not a value after the lw instruction is executed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
指令 lw {regDest}, {imm}({reg}) 将把 {reg}+imm 指向的有效地址存储的字的内容加载到 {regDest} 中,其中 inm 是 16 位立即数。
有效地址应该是4的倍数。
例如,代码
将在$t2中加载地址0x2004的内容(即$t1指向的地址是0x2000加上立即数4,得到有效地址0x2004)。
如果该地址的内容为零,您可能仍然会得到 $t2=0。
The instruction lw {regDest}, {imm}({reg}) will load in {regDest} the contents of the word stored at effective address pointed by {reg}+imm, where inm is a 16 bit immediate.
The effective address should be multiple of 4.
For example, the code
will load in $t2 the contents of address 0x2004 (that is, the address pointed by $t1 which was 0x2000 plus the immediate 4, giving effective address 0x2004).
You might still get $t2=0 if the contents of that address is zero.
0() 表示您将从寄存器的第一个块中获取它。你可以将其设置为 1 ,2 甚至 4。
如果你输入 n(),它将从你指定的第 n 个块中获取值
0() means you will get it from the first block on the register. You can make it 1 ,2 or even 4.
If you put n(), It will get the value from the nth block you specify