Skip to main content

ADD

Add the two operands and store their sum in the left operand.

OpcodeBytesCyclesFormExample
$8833add b:_, {byte}add b:1, 123
$8933add p:_, {s_byte}add p:2, 123
$d443add p:_, {pair}add p:2, 12345
$8a33add i:_, {s_byte}add i:4, 123
$d543add i:_, {s_pair}add i:4, 12345
$8b33add b:_, b:_add b:1, b:2
$8c33add p:_, p:_add p:2, p:4
$8d33add i:_, i:_add i:4, i:8
$3b21add sp, {s_byte}add sp, 123
$8f31add sp, {s_pair}add sp, 12345
Condition flagOutput
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 add is used with a framed register. For example, add sp, 123 or add ip, 123 will 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 carry has no effect for the add sp, {s_byte} form.

  • If io::stack_guard is 1, then add sp, {s_byte} and add sp, {pair} will trigger a stack fault event if the sp register becomes larger than the gp register.

Jump forms

Two forms of the jump pseudo-instruction are actually implemented as add instructions involving the ip register:

OpcodeBytesCyclesRaw formJump example
$3c21add ip, {s_byte}jump near $12_3abc
$9031add ip, {s_pair}jump far $12_3abc