Mips:将一个变量存储在另一个变量中
我正在尝试将 C 程序转换为 MIPS 汇编代码
在我的 C 代码中,我有这样一行:
int base;
int count;
count = base;
In MIPS, how will I store the value of base inside of count?我看到的唯一用于加载和存储的指令是 lw 和 sw ,它们的原型仅来自寄存器源 -> 。 ram 目的地或 ram 源 ->注册目的地。
任何帮助将不胜感激。
编辑 我希望这可以在一条指令中完成,例如
move base acc
但显然这是不可能的(至少我没有找到类似的指令示例),我选择了这个:
lw $t0, base //load base into $t0
sw $t0, count //store the value of $t0 in count
如果有一行指令可以执行此操作,那么如果有人知道的话那就更好了。
I am trying to translate a C program into MIPS assembly code
In my C code I have a line like this:
int base;
int count;
count = base;
In MIPS, how would I store the value of base inside of count? The only instructions I see for loading and storing are lw
and sw
and their prototypes only go from a register source -> ram destination or a ram source -> register destination.
Any help would be appreciated.
EDIT
I was hoping that this could be done in a single instruction, something like
move base acc
but apparently that is impossible (at least I found no example of an instruction similar to that), I opted for this:
lw $t0, base //load base into $t0
sw $t0, count //store the value of $t0 in count
If there is a one-line instruction to do this that would be better if anyone knows one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MIPS 不支持直接内存到内存的移动。 (事实上,大多数常见的 CPU 也没有,甚至 x86 也没有。)您需要使用
lw
/sw
来移动数据。从架构上讲,这是因为 MIPS 被设计为每个周期仅执行一次内存访问 - 进行内存到内存的移动将需要两次访问(一次读取,一次写入),或者停止管道。
MIPS doesn't support direct memory-to-memory moves. (Neither do most common CPUs, actually -- even x86 doesn't.) You'll need to use
lw
/sw
to move data around.Architecturally, this is because MIPS is designed to only perform a single memory access per cycle -- doing a memory-to-memory move would require two accesses (one read, one write), or stall the pipeline.
以下是在 MIPS 中执行此操作的方法
不可能在单个指令中进行内存到内存的移动。
Here's how to do it in MIPS
It is not possible to do a memory to memory move in a single instruction.