My homework is to initialize values in certain registers. We have to turn off Permit extended (pseudo) instructions and formats.
When i try to assemble the code i get this error message for line 7,8,9
Extended (pseudo) instruction or format not permitted.
Also is there a way to optimize the code? We startet Assembly language last week so im pretty new to it.
.text addi $8, $0, 1 addi $9, $0, 11 addi $10, $0, 0x1000 addi $11, $0, -1 addi $12, $0, -0x8000 addi $13, $0, 0x8000 addi $14, $0, 0xffff0000 addi $15, $0, 0x7fffffff addi $24, $0, 5322 addi $25, $0, 75
addiinstruction requires a 16 bits signed parameter. On 16 bits, you can code from -32768 (-0x8000) to +32767 (0x7fff).
addi $13, $0, 0x8000 is out of range (+32768).
And instructions 8
addi $14, $0, 0xffff0000 and 9
addi $15, $0, 0x7fffffff even more.
Initializing a registers with an argument with more than 16 significant bits requires in general two instructions. That is the purpose of macros instructions such as
li that can load in two instructions a 32 integer or
la that does the same with an address (label).
Basically, what must be done, to load 0x01234567 in $2, is first loading the high order bits with
lui (load upper immediate), then or it with the lower part of the argument.
lui $2, 0x0123 # load the upper part and clears 16 LSBs # content of $2 is 0x01230000 ori $2, $2, 0x4567 # ors with the 16 least significant bits
andi, xori) consider their operand as logical and do not perform sign extension. Operand is just is zero extended.
So, you could replace ligne 7 by
ori $13, $0, 0x8000
to have a valid initialization in one instruction.
Similarly, instruction 8 immediate has all its 16 LSB cleared and initialization can be done in a unique lui
lui $14, 0xffff
For line 9, two instructions are required
lui $15, 0x7fff ori $15, $15, 0xffff
There in no way to really optimize the code. To initialize 10 different registers, you need at least 10 instructions.
User contributions licensed under CC BY-SA 3.0