MIPS assembly language: Could someone explain to me why there is no subi instruction?

Jay59express

Senior member
Jun 7, 2000
481
0
0
Title pretty much says it all. Just wondering why there cannot be a subi (subtract immediate) instruction in the MIPS assembly language.
Thanks!
 

Jay59express

Senior member
Jun 7, 2000
481
0
0
That was So fast!
But does that explain why you cannot subtract immediately? Is it because you need to add the opposite, which means you need to negate the 2nd operand first, then add?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
instead of using subi, just use addi with a negative immediate value, if you think about it, this is what subi would do:

subi $t0, $t1, 16 # takes the value from $t1, subtracts 16, and stores it in $t0

here's what addi does:

addi $t0, $t1, -16 # takes the value from $t1, adds negative 16 (effectively subtracting 16) and stores it in $t0.

There's no benefit to having a subi instruction, just use the negative of the immediate value.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
oh, and the reason that there isn't a subi instruction, is because it was easier to build the processor without one, and addi would work just fine.
 

Jay59express

Senior member
Jun 7, 2000
481
0
0
cool, thanks man... you last post is what I was looking for, one of out homework questions asked why there was not a subi.
Thanks again