I have the follow instruction, and I don't understand why the PCSPIM is giving me the following warning:
spim:(parser) immediate value (61440) out of rainge (-32768..32767)
on line 88 of file
addiu $a, $zero, 0xF000
^
I according to the ISA, I should have
Description: Adds a register and a sign-extended immediate value and
stores the result in a register
Operation: $t = $s + imm; advance_pc(4);
Syntax: addiu $t, $s, imm
Encoding: 0010 01ss ssst tttt iiii iiii iiii iiii
If I convert addiu $a0, $zero, 0xF000 into machine code I would have
opcode | rs | rt | imm val
-------+-----+------+--------------------
0010 01|00 00|0 0100| 1111 0000 0000 0000
which should fit the instruction
I assume you meant something like this:
This is a quirk of
spimbecause it is not treating this as a pseudo-op. But, given this, it is correct to flag this.Regardless of whether you use
addioraddiuthey both have the same signed range of-32768 to 32767. The only difference is whether the instruction will generate an exception on integer overflow. That is, both instructions will do sign extend on the immediate value and not do sign extend foraddiand zero extend foraddiu.Your value
0xF000is 61440 [decimal] which is outside the allowable range for the instructions. In both cases, you'll get a sign extended value of0xFFFFF000spimsaw the0xF000and recognized that you wanted to add0x0000F000and not0xFFFFF000but wouldn't automatically generate the code because it treated theaddiuas a low level literal instruction.On the other hand,
marsdoes treat this as a pseudo-op and generates:It recognizes that you want an unsigned operation, so it has to generate instructions that produce a true unsigned addition using
adduHowever, if you rewrite your original as:
Now,
spimwill treat this as a pseudo-op and generate:And,
marsis happy with that rewrite as well