058. Adc absolute x

Connect ADC absolute,X (opcode $7D) to CPU dispatch.

Lesson 58 of 356 · tests/chapter_01_cpu/test_058_ADC_absolute_x.py

File to update

emulator/cpu/opcodes.py

Symbols to create/update

opcodes.adc_absolute_x
OPCODE_TABLE[$7D]

Why this step exists

The existing absolute_x helper consumes the little-endian base address and adds X. This handler reads the byte at that effective address and reuses the ADC instruction implemented in test 053.

Complete example implementation

# emulator/cpu/opcodes.py
def adc_absolute_x(cpu):
    addr = absolute_x(cpu)
    value = cpu.bus.read(addr)
    adc(cpu, value)

OPCODE_TABLE = {
    # ...existing entries...
    0x7D: adc_absolute_x,
}

Important invariants

  • X is applied exactly once by absolute_x
  • the effective address is not constrained to page zero
  • PC advances by three bytes total
  • the addressed value is passed to adc

Common misconception

Do not apply zero-page wrapping to an absolute indexed address; this mode may cross into the next page.

Out of scope

  • absolute,Y and indirect ADC modes
  • page-crossing timing penalties
  • 16-bit address wrapping policy beyond the existing helper

Run this lesson

uv run pytest tests/chapter_01_cpu/test_058_ADC_absolute_x.py -v