14

I am very new to Assembly language. I was reading about MIPS architecture and came to know that you have addi opcode but there is no subi opcode. Why don't we have a subi opcode?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Near-duplicate [What is the "relationship" between addi and subi?](https://stackoverflow.com/q/11981660). Some MIPS assemblers implement `subi` as a pseudo-instructions. (including the MARS simulator but not SPIM.) – Peter Cordes Nov 18 '18 at 13:35

2 Answers2

23

When you create an instruction set, you're bound by some constraints, such as the total number of instructions you can create. The MIPS creators realized that there isn't a need for subi (because you can add a negative number with addi using 2's complement), and they simply made the decision to forego making that instruction. It may have been to conserve the number of instructions, or just simply because it isn't needed.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Chris Gregg
  • 2,376
  • 16
  • 30
  • Thanks a lot. So they followed there rule, i.e "Less is more." –  Aug 02 '11 at 20:45
  • @JustAnotherProgrammer - that's probably the case. Good luck with MIPS! [Patterson and Hennessy](http://www.amazon.com/Computer-Organization-Design-Fourth-Architecture/dp/0123744938/ref=sr_1_1?ie=UTF8&qid=1312318028&sr=8-1) is a great book for learning computer architecture (the bible), and the [SPIM simulator](http://spimsimulator.sourceforge.net/) is a decent tool if you want to practice your MIPS assembly. – Chris Gregg Aug 02 '11 at 20:51
  • 1
    Why is 'sub' needed then? Can't we use 'add' to do any 'sub' operation by taking 2's complement – da4kc0m3dy Jul 27 '14 at 18:30
  • @mskd96 Yes, you could perform a `sub` that way, so it is not strictly necessary. But, unless there is another important operation that would be omitted from the ISA by including `sub`, it isn't detrimental to include it in the ISA. – Chris Gregg Jul 29 '14 at 13:57
  • 3
    @mskd96 you forgot 1 of Patterson and Hennessy's design principles: *"Make the common case fast"*. `sub` is much more common than `subi` with immediates larger than 32767 so that'll why the instruction was introduced, otherwise we can have a complete instruction set with [only 1 instruction](http://en.wikipedia.org/wiki/One_instruction_set_computer) and also very slow to do common things. "Good design demands good compromises" – phuclv Nov 13 '14 at 04:10
4

Both addi and addiu take 16-bit signed immediates as operand, so it makes no sense to add separate subi and subiu opcodes.

ninjalj
  • 42,493
  • 9
  • 106
  • 148