subu
Subtract unsigned (no overflow trap)
Subtracts the third register, or an immediate, from the second and stores the difference in the first, wrapping on overflow instead of trapping.
Used in
- Maximum and unsigned distanceMIPS assembly
- Byte length of a stringMIPS assembly
- A bouncing ballMIPS assembly
Forms
subu , ,
Pseudo-instructions
The processor does not have these forms. The assembler replaces each of them with one or more real instructions. Open a row to see them.
-
Set $t1 to ($t2 minus 32-bit immediate), no overflow
Operands
$t1- Any general-purpose register,
$0to$31, using its numeric or named spelling, such as$8or$t0($zerois$0;$rais$31). $t2- A general-purpose register. It may be the same register as
$t1. $t3- A general-purpose register. It may be the same register as
$t1. imm32- A 32-bit immediate,
-2147483648to4294967295. A pseudo-instruction that takes one uses the register$atas a temporary, so$atloses the value it held.
No exception is raised on overflow; the result wraps modulo 2^32. The most common subtract instruction in practice.
# Subtract 1 from zero without signed-overflow trapping. Inspect $t2: 0xFFFFFFFF.
li $t0, 0
subu $t2, $t0, 1