Can someone explain the use of "ori" here? I know it's bitwise OR, but I don't know how it works or why it's 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
ori $s0, $zero, 0x5
ori $s1, $zero, 0x7
The two instructions load a constant of 0x05 into register $s0 and 0x07 into register $s1.
MIPS doesn't has an instruction that directly loads a constant into a register. Therefore logical OR with a operand of zero and the immediate value is is used as a replacement. It has the same effect as move. Translated to c-style code these two lines are:
$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. Translated to code this would be.
$s0 = 0 + 0x05;
$s1 = 0 + 0x07;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With