la, li, and lui Instructions


The following gives three load immediate instructions.
la rd, mem         # load address
Loads the destination register with the effective address (NOT the contents of the memory location) of the specified data item.

li rd, imm         # load immediate
Loads the destination register with the value of an expression that can be computed at assembly time.

lui rd, imm         # load upper immediate
Loads the most-significant half of a register with the expression’s value. The least-significant half of the register is filled with zeros. Value of the expression must be in the range [0, 65535] = [0, 216-1] = [0, (FFFF)16].
la li lui
       .data
 msg:  .ascii  "Class, "
       .ascii  "Greeting"
       .byte   0

       .text  
       la  $a0, msg+7
       li  $v0, 4
       syscall
   .text 
   li  $a0, -10+2
   li  $v0, 1
   syscall
   .text 
   lui  $a0, 1
   li   $v0, 1
   syscall
Output Output Output










Note that the immediate operand in li and lui is an expression. The expression includes several operators such as * (multiplication), / (division), % (remainder), etc. However, (the instructor believes) the MARS and Spim are not able to handle most expressions, e.g., -10+2 is fine in the above code for Spim, but not for MARS and 10*2 does not work for both simulators.




      “Take it moment by moment, and you will find that    
      we are all, as I’ve said before, bugs in amber.”    
      ― Kurt Vonnegut