addu
and subu
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
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
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 | ||
|
|