MIPS 加载字语法

发布于 2024-08-22 12:07:34 字数 123 浏览 3 评论 0原文

如果我想从基地址位于 $a0 且偏移量 $t2 的内存中加载一个值,为什么我不能执行以下操作:

lw  $s2, $a1($t2)

那么上面的表达式的等价物是什么?

If I want to load a value from a memory which base address is at $a0 and off set $t2, why can't I do the following:

lw  $s2, $a1($t2)

so what is the equivalent of the expression above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

会傲 2024-08-29 12:07:34

你不能这样做,因为没有 MIPS 指令编码支持这样的事情。您需要自己进行加法:

add $a2, $a1, $t2
lw  $s2, 0($a2) 

lw指令编码如下:

1000 11ss ssst tttt iiii iiii iiii iiii

其中sssss是源寄存器编号,ttttt是目标寄存器数字,iiiiiiiiiiiiiiii 是立即数。该编码(并且没有替代指令编码)中没有空间使用两个寄存器来生成内存地址。从上面的示例中编码的特定机器指令是:

1000 1100 1101 0010 0000 0000 0000 0000

由于立即数是 0,因此 $s2 是寄存器 18$a2 是寄存器6

You can't do that because there's no MIPS instruction encoding that supports such a thing. You need to do the addition yourself:

add $a2, $a1, $t2
lw  $s2, 0($a2) 

The lw instruction encoding looks like this:

1000 11ss ssst tttt iiii iiii iiii iiii

Where sssss is the source register number, ttttt is the destination register number, and iiiiiiiiiiiiiiii is the immediate. There's no room in that encoding (and no alternate instruction encodings) that use two registers to generate the memory address. The specific machine instruction that would get encoded from the example above is:

1000 1100 1101 0010 0000 0000 0000 0000

Since the immediate is 0, $s2 is register 18 and $a2 is register 6.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文