I'm unaware that MIPS even has a proper subi
instruction (though some environments may implement a macro for it).
Since you're subtracting an immediate value, you can just provide the negation of it to the addi
instruction:
addi $r1, $r2, -42 ; equivalent to subi $r1, $r2, 42
The immediate operand is a two's complement value which means it's perfectly capable of being a negative number and the way that two's complement works means that you can add a negative number in an unsigned manner and that gives the same result as subtracting (since you wrap around).
For example, -42
in 16-bit two's complement is the unsigned value 65494
. When you add 50
and 65494
wrapping around at 65536, you end up with:
50
+ 65494 (ie, -42)
-----
65544 (overflow, so
- 65536 we wrap at 64K)
-----
8 (identical to "50 - 42")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…