sub
and neg
Instructions
rs
and rt
), and places the result in the destination register rd
.
The unary operation neg
(“taking the 2’s complement”) performs its function on the value in the source and places the result in the destination.
sub rd, rs, rt
# subtract with overflow
rt
from the contents of rs
, or it can subtract the contents of the immediate from the rs
value.
Subtract puts the result in the destination register.
When the true result’s sign differs from the destination register’s sign, the machine signals an overflow exception.
neg rd, rs
# negate with overflow
rs
and puts the result in the destination register rd
.
If the value in rs
is -2147483648=2-31, the machine signals an overflow exception.
sub |
Char '7' to Int 7 | neg |
---|---|---|
.data X: .byte 10 Y: .word -20 .text lb $t0, X lw $t1, Y sub $a0, $t1, $t0 li $v0, 1 syscall |
.text li $t0, -20 move $t1, $t0 neg $t1, $t1 sub $a0, $t1, $t0 li $v0, 1 syscall |
|
Output | Output
(
|
Output |
7 (integer) |