A good answer might be:

sw $12 , 0xFFF8($13)    or    sw $12 , -8($13)

Setting up the Base Register

The first instruction of the answer expresses minus eight using 16-bit two's complement. This is the bit pattern that is actually contained in the machine instruction. This is awkward to read and to calculate. The second instruction uses signed decimal notation to specify minus eight. The assembler translates this assembler instruction into exactly the same machine instruction as the first assembler instruction.

By using a 32-bit base register and an offset a 32-bit lw or sw instruction can reference memory. But how does the base address get into the base register? This is where the lui (load upper immediate) instruction is useful. It copies its 16-bit immediate operand to the upper two bytes of the designated register.


lui  t,const  # upper two bytes of $t <-- two byte const 
              # lower two bytes of $t <-- 0x0000

Sometimes this is all that you need. For example, say that memory is as in the picture, and that you want to load the word at 0x00040010 into $12. The lui instruction can set up the base register:

QUESTION 9:

lui $13, 0x________
lw  $12, 10($13)

Complete the lui instruction.