Definition
The ADD Instruction is an arithmetic instruction that adds two operands together. It is a fundamental instruction belonging to the broader category of ALU Instructions, which perform arithmetic and logical operations in a processor's arithmetic logic unit.
GameBoy Example: ADC H
In the GameBoy processor context, the ADC H instruction (add with carry, register H) is used as a worked example to illustrate how an ALU instruction affects registers and flags. The example demonstrates running the same instruction multiple times and observing how the internal register values — including the accumulator (REG A) and the flags register (REG F) — change after each execution.
When running the example:
- The result of REG A matches the expected outcome after each instruction.
- After three additional executions of the instruction, REG A reaches the value 20 (0x14).
- On the fourth instruction, a carry occurs from the lower nibble to the higher nibble (REG A transitions from 0x0F to 0x14).
- This nibble overflow is reflected in the flags register F at bit index 1 (the Half Carry flag).
Exercise: Implementing executeALUInstruction(byte instr)
The exercise asks the reader to complete the executeALUInstruction(byte instr) function so that an ADD H instruction can be executed in the model. The behavior to implement is:
- The expected outcome is the sum of the contents of register H and register A.
- The expected outcome is stored in register A.
- The Zero flag, F(3), is set if the result is 0x00.
- The Subtract flag, F(2), is cleared.
- The Half Carry flag, F(1), is only set if a carry occurred from the lower to the higher nibble.
- The Carry flag, F(0), is only set if an overflow occurs.
These semantics (sum of operands stored in destination, with Z/N/H/C flag updates) are characteristic of ADD-family instructions across 8-bit processors such as the GameBoy's Sharp LR35902 CPU.
Related Concepts
- ALU Instruction: The ADD instruction is part of the broader ALU Instruction family that performs arithmetic and logical operations.
- executeALUInstruction: The code artifact (function) that implements ALU instructions, including ADD H, in the GameBoy processor verification model.
Caveats
- The evidence provided focuses on an 8-bit GameBoy-style ADD H example and a transient-execution attack context on x86 Fused Multiply-Add instructions; these are distinct instruction families. The general definition above is supported only by the GameBoy evidence chunk; broader claims about ADD across ISAs are not directly supported by the provided evidence.