SUBTRACT
Subtract the right operand from the left operand, storing the difference in the left operand.
| Opcode | Bytes | Cycles | Form | Example |
|---|---|---|---|---|
| $91 | 3 | 1 | SUBTRACT B:_, B:_ | SUBTRACT B:1, B:2 |
| $92 | 3 | 3 | SUBTRACT P:_, P:_ | SUBTRACT P:2, P:4 |
| $93 | 3 | 3 | SUBTRACT I:_, I:_ | SUBTRACT I:4, I:8 |
| Condition flag | Output |
|---|---|
| zero (ZF) | If the difference is zero, this flag is 1; otherwise it is 0. |
| negative (NF) | If the signed difference is a negative number, this flag is 1; otherwise it is 0. |
| overflow (OF) | If the difference exceeds the register's signed range, this flag is 1; otherwise it is 0. |
| carry (CF) | If the difference underflows the register's unsigned range, this flag is 0; otherwise it is 1. |
Notes
-
SUBTRACTdoes not support immediate operands such asSUBTRACT I:_, 123. Instead, use a negative addition such asADD I:_, -123. Chombit's design ensures that negative addition sets the condition flags the same as subtraction. -
If the previous instruction was WITH CARRY, and CF is 0, then an extra 1 will be subtracted. This is the subtract-with-carry model familiar from ARM and 6502 processors.
-
Note: Some other CPU architectures such as x86 and Z80 use the "subtract-with-borrow" model instead of "subtract-with-carry." For those CPUs, an extra 1 is subtracted when CF=1 (rather than CF=0), and an underflow would be indicated by CF=1 (rather than CF=0).