Mips:将一个变量存储在另一个变量中

发布于 2025-01-01 18:21:00 字数 557 浏览 0 评论 0原文

我正在尝试将 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 技术交流群。

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

发布评论

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

评论(2

三五鸿雁 2025-01-08 18:21:00

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.

时间你老了 2025-01-08 18:21:00

以下是在 MIPS 中执行此操作的方法

la $t0, base     // load the address of "base"
la $t1, count    // load the address of "count"
lw $t2, 0($t0)   // load the data at location "base"
sw $t2, 0($t1)   // store that data at location "count"

不可能在单个指令中进行内存到内存的移动。

Here's how to do it in MIPS

la $t0, base     // load the address of "base"
la $t1, count    // load the address of "count"
lw $t2, 0($t0)   // load the data at location "base"
sw $t2, 0($t1)   // store that data at location "count"

It is not possible to do a memory to memory move in a single instruction.

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