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

5

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.

assembly
mips
mars-simulator
spim
immediate-operand
asked on Stack Overflow May 11, 2016 by Miguel • edited Mar 22, 2020 by Peter Cordes

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0