lhu, lbu, and move Instructions


The following gives two more load instructions and the move instruction.
lhu rd, mem         # load unsigned halfword
Loads the least-significant bits of the destination register with the contents of the halfword that is at the memory location specified by the effective address. Because the machine treats the loaded halfword as an unsigned value, it fills the two most-significant bytes of the destination register with zeros. If the effective address is not even, the machine signals an address error exception.

lbu rd, mem         # load unsigned byte
Loads the least-significant byte of the destination register with the contents of the byte that is at the memory location specified by the effective address. Because the machine treats the loaded byte as an unsigned value, it fills the three most-significant bytes of the destination register with zeros.

move rd, rs         # move register contents
Moves the contents of source register to the destination register.
lhu lbu & move
        .data
 val0:  .byte   0
 val1:  .byte   1
 val2:  .byte   2

        .text
        lhu  $a0, val1
        li   $v0, 1
        syscall
        .data
 val0:  .byte   0 
 val1:  .byte   1
 val2:  .byte   2 

        .text 
        lhu  $a0, val0
        li   $v0, 1
        syscall
       .data
 val:  .byte   -10 

       .text 
       lbu   $t0, val
       move  $a0, $t0
       li    $v0, 1
       syscall
Output Output Output













      Knock Knock!    
      Who’s there?    
      Cash.    
      Cash who?    
      I knew you were a nut!