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.