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).