Range of immediates in lui instruction

2019-08-28 01:01发布

问题:

I'm not sure what is the range bound for the immediate in lui instruction.

When I assemble:

lui $t0,32768

It successfully went without errors.

However,

lui $t0,-32768 

notified that -32768 out of range.

回答1:

In MIPS the immediate in I-type instructions is always 16-bit long. That means the range will be [0, 65535] if the assembler treats it as unsigned, and [-32768, 32767] for the signed case

However what you can use in the assembly depends on the assembler

For example some assemblers like shell-storm and WeMips accept constants in [-32768, 65535] which is a mix of both 16-bit signed and unsigned, MIPS Converter only accepts hexadecimal values but WebMIPSASM accepts even huge values like 9223372036854775807 and truncate the result to 16 bits