[英]What's the difference between using ori and addi to initialize a value in MIPS?
[英]what is the use of ori in this part of MIPS code?
有人可以在这里解释“ori”的使用吗? 我知道它是按位OR,但我不知道它是如何工作的或者为什么需要它。
#objective of the program is to add 5 and 7
.data #variable declaration follow this line
.text #instructions follow this line
main:
ori $s0, $zero, 0x5
ori $s1, $zero, 0x7
add $t0, $s0, $s1
li $v0,10 # required for only QtSPIM
syscall # required for only QtSPIM
#end of program
ori $s0, $zero, 0x5
ori $s1, $zero, 0x7
这两条指令将寄存器$ s0和0x07的常量0x05加载到寄存器$ s1中。
MIPS没有直接将常量加载到寄存器中的指令。 因此,将操作数为零且立即值的逻辑OR用作替换。 它与移动具有相同的效果。 转换为c风格的代码,这两行是:
$s0 = 0 | 0x05;
$s1 = 0 | 0x07;
你也可以使用:
addi $s0, $zero, 0x5
addi $s1, $zero, 0x7
这做同样的事情,但使用add而不是逻辑或。 转换为代码,这将是。
$s0 = 0 + 0x05;
$s1 = 0 + 0x07;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.