lw 在 C 或 C++ 中如何表示?
那么,例如,会是这样的:
lw $t1, 0($t0)
或
lw $t2, 8($t0)
翻译为 C 或 C++ 语言?我的意思是我正在将地址中的一个字加载到寄存器中,我明白了。数组是一个类似的概念吗?或者,什么?
提前致谢。
So, for example, what would something like this:
lw $t1, 0($t0)
or
lw $t2, 8($t0)
Translate to in C or C++? I mean I'm loading a word from the address into a register, I get that. Is an array a similar concept, or, what?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是“加载字”指令。它将 4 字节字从内存中的地址存储在寄存器 $t0 中的位置加载到寄存器 $t1 中。
c/c++ 中没有等效的构造。该指令非常流行,在大多数需要内存访问的结构中使用,例如:
可以翻译为类似的内容(假设 $t0 包含指针“p”)
这里第一条指令将变量加载到寄存器中,第二条指令修改它第三个将其写回内存
This is "load word" instruction. It loads 4-byte word from memory at location which address is stored in register $t0, into register $t1.
There is no equivalent construction in c/c++. This instruction is very popular and used in most constructions where memory access in required, for example:
may be translated to something like (given $t0 contains pointer 'p')
Here the first instruction loads the variable into a register, the second modifies it and the third writes it back into the memory
我认为你无法编写完全相同的代码。您可以执行以下操作:
您也可以在检索值时应用偏移量:
有一个注释:您无法在语言中指定所需的
register
。您可以做的是提示编译器将word
放入register
中:I think you can't write exactly similar code. You could do the following:
You could apply the offset when retrieving the value also:
There is a note: You can't specify the required
register
in the language. What you can do is to give a hint to the compiler to putword
in aregister
:对于第一行:
int t1, *t0; ... t1 = *t0
或t1 = t0[0]
甚至int t0, t1; ... t1 = t0 。
对于第二个:
int t2 = t0[2]
,也许,或者int t2 = t0.thirdThing
。但你无法确定。可能是 char *x, **y; x = y[2]; 如果我们了解地址如何进入寄存器,可能会更清楚地了解原始代码。
For the first line:
int t1, *t0; ... t1 = *t0
ort1 = t0[0]
or evenint t0, t1; ... t1 = t0
.For the second:
int t2 = t0[2]
, maybe, or perhapsint t2 = t0.thirdThing
.But you can't know for sure. It could be
char *x, **y; x = y[2];
If we saw how the address got into the register it might shed more light on the original code.假设您使用的是 MIPS32(因此具有 32 位内存寻址),那么它们所做的事情非常简单。
其作用是将内存地址 t0 字节偏移 0 处的值加载到 t1 寄存器中。
其作用是将内存地址 t0 字节偏移 8 处的值加载到 t2 寄存器中。
假设您有一个内存地址 0x12345678。那么 MIPS 程序集本质上会执行以下操作:
Assuming you are using MIPS32 (and hence have 32-bit memory addressing) then its pretty easy what they do.
What this does is load the value at byte offset 0 from memory address t0 into the t1 register.
What this does is load the value at byte offset 8 from memory address t0 into the t2 register.
Lets assume you have a memory address 0x12345678. Then the MIPS assembly is, essentially, doing the following: