C语言 MIPS汇编语言中“move”和“li”的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19827522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:54:29  来源:igfitidea点击:

Difference between "move" and "li" in MIPS assembly language

cassemblymips

提问by user2492270

I was practicing converting C code into MIPS assembly language, and am having trouble understanding the usage of moveand liin variable assignment.

我正在练习将 C 代码转换为 MIPS 汇编语言,但在理解变量赋值中move和的用法时遇到了麻烦li

For example, to implement the following C line in MIPS:

例如,要在 MIPS 中实现以下 C 行:

int x = 0;

If I understand it correctly (I highly doubt this, though), it looks like both of these work in MIPS assembler:

如果我理解正确(不过我对此表示高度怀疑),看起来这两个都可以在 MIPS 汇编器中工作:

move $s0, $zero
li $s0, $zero

Am I wrong? What is the difference between these two lines?

我错了吗?这两条线有什么区别?

回答by duskwuff -inactive-

The moveinstruction copies a value from one register to another. The liinstruction loads a specific numeric value into that register.

move指令将值从一个寄存器复制到另一个寄存器。该li指令将特定数值加载到该寄存器中。

For the specificcase of zero, you can use either the constant zero or the zero register to get that:

对于零的特定情况,您可以使用常量零或零寄存器来获得:

move $s0, $zero
li   $s0, 0

There's no register that generates a value other than zero, though, so you'd have to use liif you wanted some other number, like:

但是,没有寄存器可以生成零以外的值,因此li如果您想要其他数字,则必须使用,例如:

li $s0, 12345678