ADD
Add the two operands and store their sum in the left operand.
| Opcode | Bytes | Cycles | Form | Example |
|---|---|---|---|---|
| $88 | 3 | 3 | ADD B:_, {BYTE} | ADD B:1, 123 |
| $89 | 3 | 3 | ADD P:_, {S_BYTE} | ADD P:2, 123 |
| $D4 | 4 | 3 | ADD P:_, {PAIR} | ADD P:2, 12345 |
| $8A | 3 | 3 | ADD I:_, {S_BYTE} | ADD I:4, 123 |
| $D5 | 4 | 3 | ADD I:_, {S_PAIR} | ADD I:4, 12345 |
| $8B | 3 | 3 | ADD B:_, B:_ | ADD B:1, B:2 |
| $8C | 3 | 3 | ADD P:_, P:_ | ADD P:2, P:4 |
| $8D | 3 | 3 | ADD I:_, I:_ | ADD I:4, I:8 |
| $3B | 2 | 1 | ADD SP, {S_BYTE} | ADD SP, 123 |
| $8F | 3 | 1 | ADD SP, {S_PAIR} | ADD SP, 12345 |
| Condition flag | Output |
|---|---|
| zero (ZF) | If the sum is zero, this flag is 1; otherwise it is 0. |
| negative (NF) | If the signed sum is a negative number, this flag is 1; otherwise it is 0. |
| overflow (OF) | If the sum exceeds the register's signed range, this flag is 1; otherwise it is 0. |
| carry (CF) | If the sum exceeds the register's unsigned range, this flag is 1; otherwise it is 0. |
The condition flags are only modified when
ADDis used with a framed register. For example,ADD SP, 123orADD IP, 123will NOT affect any condition flags.
Notes
-
If the previous instruction was WITH CARRY, and the left operand is a framed register, and CF is 1, then 1 is added to the sum. For example,
WITH CARRYhas no effect for theADD SP, {SBYTE}form. -
If
IO::STACK_GUARDis 1, thenADD SP, {SBYTE}andADD SP, {PAIR}will trigger a stack fault event if theSPregister becomes larger than theGPregister.
Jump forms
Two forms of the JUMP pseudo-instruction are actually implemented as ADD instructions involving the IP register:
| Opcode | Bytes | Cycles | Raw form | Jump example |
|---|---|---|---|---|
| $3C | 2 | 1 | ADD IP, {S_BYTE} | JUMP NEAR $12_3ABC |
| $90 | 3 | 1 | ADD IP, {S_PAIR} | JUMP FAR $12_3ABC |