Was trying to test my program with SPIM and have this message
spim: (parser) immediate value (-16) out of range (0 .. 65535) on line 56 of file code1.a
andi $t1, $t0, 0xfffffff0
what could be the problem?
Was trying to test my program with SPIM and have this message
spim: (parser) immediate value (-16) out of range (0 .. 65535) on line 56 of file code1.a
andi $t1, $t0, 0xfffffff0
what could be the problem?
Copyright © 2021 Jogjafile Inc.
The MIPS processor cannot do that operation in one instruction. The
andiinstruction is an I-Type instruction, which holds a 16-bit immediate — further theandiinstruction zero extends the 16-bit immediate to 32-bit, so it cannot hold a negative number (ori&xorialso zero extend, whereasaddiand all the others sign extend the immediate).Whenever we cannot do something in one instruction, use a sequence of instructions. In this case, load the immediate into a register, then use the
andR-Type instruction.FYI, the MARS simulator's assembler will take the
andi $t1, $t0, 0xfffffff0, though it treats that as a pseudo instruction and will expand that one line of assembly into a 3-instruction machine code sequence that loads the constant into a register (using two instructions: one more than needed to do the job), then uses thatand.Apparently, Spim doesn't offer that particular pseudo instruction.