Skip to content
STIMSMITH

ADC Instruction

Concept WIKI v1 · 6/20/2026

The ADC (Add with Carry) instruction is an arithmetic operation commonly found in ALU instruction sets. In the modeled context, it computes A = A + operand + Cin (carry-in), storing the result back in register A and updating the processor's flag register accordingly.

Overview

The ADC instruction (Add with Carry) is an ALU arithmetic operation. In the documented processor model, it is executed by invoking the executeALUInstruction(byte instr) task with the corresponding opcode (for example, ADC H is encoded as 8'h8C).

The semantic effect of an ADC H instruction is to compute:

A = A + H + Cin

where Cin is the current value of the carry flag of the flag register.

Flag Effects

Executing an ADC instruction updates the flag register (F) as follows:

  • Zero flag, F(3): Set if the result equals 0x00.
  • Subtract flag, F(2): Cleared.
  • Half Carry flag, F(1): Set only when a carry occurs from the lower nibble to the higher nibble.
  • Carry flag, F(0): Set only when an overflow (carry out of the highest bit) occurs.

Worked Example from the Model

In the gameboyprocessor class used as a golden reference model, registers are initialized to constant values: A=0, B=1, C=2, D=3, E=4, F=0, H=5, L=6. Because LOAD instructions are not implemented in the simplified model, only registers A and F change during execution.

Executing 0x8C (ADC H) once produces:

A = 0 + 5 + 0 = 5 (0x05)

Running the same instruction repeatedly accumulates the value of H (5) into A while honoring the carry flag. After the fourth consecutive execution, the lower-nibble overflow (from 0x0F to 0x14) is reflected in the half-carry flag bit at index 1 of register F.

Distinction from ADD

The exercise counterpart, ADD H, performs A = A + H without including the carry-in bit. The ADC variant therefore differs from ADD by the inclusion of Cin from the flag register.

Verification Context

In the layered testbench methodology used to verify the DUT, the same stimulus (0x8C) is fed both to the hardware device under test and to the object-oriented model. The model's executeALUInstruction(byte instr) task must replicate the DUT's register and flag behavior so that a scoreboard can compare outputs.

CITATIONS

4 sources
4 citations
[1] The ADC instruction computes A = A + operand + Cin, combining the operand with the current carry flag value. Golden reference
[2] The opcode for ADC H in the model is 0x8C and is dispatched via the executeALUInstruction(byte instr) task. Golden reference
[3] ADC sets the zero flag F(3) if the result is 0x00, clears the subtract flag F(2), sets the half-carry flag F(1) on lower-to-higher nibble carry, and sets the carry flag F(0) on overflow. Golden reference
[4] Executing ADC H four times with H=5 starting from A=0 causes A to reach 20 (0x14), with the lower-to-higher nibble overflow reflected in F(1) on the fourth execution. Golden reference