li $v0,12 == ori $v0,zero,12
The load immediate pseudoinstruction is useful for loading a register with an integer value. Here is another example:
li $t2,-153
This puts the two's complement representation of -15610
into register $t2.
However, this can not be done with
ori
because the immediate field of that instruction must be a
16-bit unsigned integer
(which is zero-extended to 32 bits upon execution).
Because the immediate value of the
li
is negative, a different translation is used:
li $v2,-153 == addiu $v2,$0,-153
(Remember that addiu
performs two's complement addition with its operands. The
u
means that overflow does not cause a trap).
The extended assembler translates
li
into different basic instructions depending on the sign of the immediate value.