简体   繁体   English

在这部分MIPS代码中ori的用途是什么?

[英]what is the use of ori in this part of MIPS code?

Can someone explain the use of "ori" here? 有人可以在这里解释“ori”的使用吗? I know it's bitwise OR, but I don't know how it works or why it's needed here. 我知道它是按位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

The two instructions load a constant of 0x05 into register $s0 and 0x07 into register $s1. 这两条指令将寄存器$ s0和0x07的常量0x05加载到寄存器$ s1中。

MIPS doesn't has an instruction that directly loads a constant into a register. MIPS没有直接将常量加载到寄存器中的指令。 Therefore logical OR with a operand of zero and the immediate value is is used as a replacement. 因此,将操作数为零且立即值的逻辑OR用作替换。 It has the same effect as move. 它与移动具有相同的效果。 Translated to c-style code these two lines are: 转换为c风格的代码,这两行是:

  $s0 = 0 | 0x05;
  $s1 = 0 | 0x07;

You could also use: 你也可以使用:

  addi $s0, $zero, 0x5
  addi $s1, $zero, 0x7

This does the same thing, but uses add instead of logical or. 这做同样的事情,但使用add而不是逻辑或。 Translated to code this would be. 转换为代码,这将是。

  $s0 = 0 + 0x05;
  $s1 = 0 + 0x07;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM