sub

Subtract with overflow trap

Subtracts the third register, or an immediate, from the second and stores the difference in the first, trapping if the signed result overflows.

Forms

  • sub , ,

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.

Operands

$t1
Any general-purpose register, $0 to $31, using its numeric or named spelling, such as $8 or $t0 ($zero is $0; $ra is $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.
imm
An immediate value: a signed 16-bit value (-32768 to 32767) or a 32-bit value (-2147483648 to 4294967295). The size your value needs decides which real instructions the assembler uses. Open the row to see them for each size.

Raises an overflow exception if the true result does not fit in 32 bits. Use 'subu' when overflow should be silently ignored.

# Initialize both inputs, then execute sub with initialized inputs. Inspect $t2: 4.
li $t0, 7
li $t1, 3
sub $t2, $t0, $t1