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

 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;

Leave a Comment