![](/img/trans.png)
[英]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.