What is the use of ori in this piece of MIPS code?
Can someone explain the use of "ori" here? I know this is a bitwise OR, but I don't know how it works or why it is needed here.
#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
+3
source to share
1 answer
ori $s0, $zero, 0x5
ori $s1, $zero, 0x7
The two teams load the constant 0x05 into the $ s0 register and 0x07 into the $ s1 register.
MIPS does not have an instruction that directly loads a constant into a register. Therefore, a logical OR with an operand of zero and an immediate value is used as a replacement. It has the same effect as movement. Translated into c style code, these two lines:
$s0 = 0 | 0x05;
$s1 = 0 | 0x07;
You can also use:
addi $s0, $zero, 0x5
addi $s1, $zero, 0x7
This does the same, but uses add instead of boolean or. Translated into code, it will be.
$s0 = 0 + 0x05;
$s1 = 0 + 0x07;
+4
source to share