Skip to content
STIMSMITH

ADD Instruction

Concept WIKI v1 · 6/20/2026

ADD is a generic arithmetic instruction found across many instruction set architectures that performs addition between two operands. In the GameBoy processor exercise context, ADD H refers to adding the contents of register H to the accumulator A, storing the result back in A, and updating the flags (Zero, Subtract cleared, Half Carry, Carry) according to defined conditions. ADD is part of the broader ALU Instruction family.

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.

CITATIONS

4 sources
4 citations
[1] ADD is an arithmetic instruction that adds two operands and belongs to the ALU instruction family. GameBoy processor — ADD/ADC example and executeALUInstruction exercise
[2] In the GameBoy context, the ADC H instruction adds register H to register A and updates Z, N, H, and C flags according to defined conditions. GameBoy processor — ADD/ADC example and executeALUInstruction exercise
[3] Running the ADD instruction repeatedly causes a carry from the lower nibble to the higher nibble (e.g., 0x0F -> 0x14), which is reflected in flag F at bit index 1. GameBoy processor — ADD/ADC example and executeALUInstruction exercise
[4] The exercise requires implementing executeALUInstruction so that ADD H computes A = H + A, clears F(2), sets F(3) when result is 0x00, sets F(1) on lower-to-higher nibble carry, and sets F(0) on overflow. GameBoy processor — ADD/ADC example and executeALUInstruction exercise