How to load 32 bit constant to a register without using LUI

Viewed 539

I am trying to load a 32-bit constant 0x1234ABCD to register $t0 in MIPS assembly. However, I am not able to use lui to do so. My instinct is to use two addi, but I am not sure how to do so. I would necessarily need 2 or more to get the 32 bits of information. I need to get the upper bits set somehow without lui. What is a good way to approach replicating lui without using it?

1 Answers

You may use for example ori combined with sll to load a 32 bit constant in 3 instructions without using lui:

  ori $t1, $zero, 0x1234  # load the upper half in the lower bits of $t1
  sll $t1, $t1, 16        # move them to the upper half
  ori $t1, $t1, 0xABCD    # combine with the lower half
Related