addu and subu Instructions


The unsigned instructions (addu, subu, etc.) treat the values as unsigned, rather than 2’s complement—these instructions are usually used to compute addresses.
addu rd, rs, rt         # add without overflow
Computes the two’s complement sum of two 32-bit values. It adds the contents of rs to the contents of rt, or it can add the contents of rs to the immediate value. Add (without overflow) puts the result in the destination register. Overflow exceptions never occur.

subu rd, rs, rt         # subtract without overflow
Computes the two’s complement difference for two 32-bit values. This instruction subtracts the contents of rt from the contents of rs, or it can subtract the contents of the immediate from the rs value. Subtract (without overflow) puts the result in the destination register. Overflow exceptions never happen.
add addu subu
    .data
 X: .byte  1
 Y: .word  0x7FFFFFFF

  # largest signed word is
  #   0x7FFFFFFF = 231-1
  # = 2,147,483,647

    .text 
    lb   $t0, X
    lw   $t1, Y 
    add  $a0, $t1, $t0
    li   $v0, 1
    syscall
    .data
 X: .byte  1
 Y: .word  0x7FFFFFFF

  # largest signed word is
  #   0x7FFFFFFF = 231-1
  # = 2,147,483,647

    .text 
    lb    $t0, X
    lw    $t1, Y 
    addu  $a0, $t1, $t0
    li    $v0, 1
    syscall
    .data
 X: .byte  1
 Y: .word  0x80000000

  # smallest signed word is
  #   0x80000000 = -231
  # = -2,147,483,648

    .text 
    lb    $t0, X
    lw    $t1, Y 
    subu  $a0, $t1, $t0
    li    $v0, 1
    syscall
Output Output Output



 




 




 

addu
     .text 
     li    $t0, 1
     li    $t1, -2 
     addu  $a0, $t1, $t0
     li    $v0, 1
     syscall
      
 
    
Output

 















      This morning I used redbull instead of water to make my coffee.    
      After 15 minutes of driving on the highway, I realized I left my car at home!