In a MIPS assembly `addi` instruction, how is a hexadecimal immediate interpreted?

Miguel picture Miguel · May 11, 2016 · Viewed 10.1k times · Source

Is there is a standard or recommendation for how the addi instruction (and others) should be interpreted in assembly, when hexadecimal immediate values are used?

Example:

addi $t0, $zero, 0xffff

I was expecting this to mean the same as addi $t0, $zero, -1 where 0xffff would be sign extended to 0xffffffff, as is done by the processor, but was surprised by the fact that the assembler of the Mars simulator interprets hexadecimals as 32bit unsigned numbers and tries to do addi $t0, $zero, 0x0000ffff as a pseudo-instruction (if pseudo-instructions are enabled).

To be clear, MARS's assembler assembles that addi $t0, $zero, 0xffff pseudo-instruction to multiple machine instructions which create that constant (65535 = 0xffff) in a register and then add it, if pseudo-instructions are enabled. MARS's simulator simulates instructions like 0x2008ffff (addi $t0, $zero, -1) correctly.

The SPIM assembler just aborts with an error.

What I would like to know is if assemblers always interpret this way, and if there is someplace where this is written or explained as I could not find anything.

Answer