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, {SBYTE} form.

  • If IO::STACK_GUARD is 1, then ADD SP, {SBYTE} 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