0
votes

Does li (load immediate) Pseudo-Instruction in MIPS loads the constant into the register differently based on the sign and size of the constant? Is li translated into different instructions when for example the constant is a 16-bit number in two's complement (-2^15 <= k < 2^15) in contrast to a positive number(0 <= k < 2^16)? what about 32-bit numbers?

The links that I found did not address it specifically. That would kind, if you explain it with examples (I use MARS simulator).

1
Load immediate is always sign-extended if that's what you are asking – Konrad Lindenbach
@KonradLindenbach: I'm asking how li is translated into actual instructions (as li is a Pseudo-Instruction) when the constant is a 16-bit positive or negative number. Is it translated into same sequence / set of instructions or based on the sign of number, different instructions are used? And what instructions are used for 32-bit numbers? – Infinity

1 Answers

4
votes

LI gets translated into a single instruction by the assembler when the immediate constant can be represented as a 16 bit two's complement number. (Typically addiu $dst, 0, imm).

LI is translated by the assembler into LUI (load upper immediate) followed by ORI when the immediate constant is too large to be represented as a 16 bit two's complement number.