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, {s_byte}form. -
If
io::stack_guardis 1, thenadd sp, {s_byte}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 |