go to previous page   go to home page   go to next page hear noise

Answer:

A byte


Loading a Single Byte

There are two instructions that load a byte from a memory address. The address of the byte is calculated at run time by adding an offset to a base register (just as with the load word and store word instructions). The instructions differ in how the 8-bit byte is put into the 32-bit register.

lb   t,off(b)  # $t <— Sign-extended byte 
               # from memory address b+off
               # b is a base register. 
               # off is 16-bit two's complement.

The lb instruction loads the byte from memory into the low order eight bits of the register. These are bits 0-7 of the register. Then it copies bit 7 to bits 8-31 of the register (all bits to the left of bit 7).

Another way to say this is that the lb instruction loads the register with a 32-bit sign extended version of the byte at the designated address. Use the lb instruction when the byte is regarded as an 8-bit signed integer in the range -128...+127 and you want a 32-bit version of the same integer.

lbu   t,off(b) # $t <— Zero-extended byte 
               # from memory address b+off
               # b is a base register. 
               # off is 16-bit two's complement.

The lbu instruction fills bits 8-31 of the register with zeros. Use this instruction when the byte is regarded as a ascii character or 8-bit unsigned integer.


QUESTION 2:

What is put in register $10 when the following instruction is executed:

lb    $10,7($8)
  

What is put in register $12 when the following instruction is executed:

lbu    $12,7($8)