151. Cmp absolute x
add CMP absolute,X opcode ``0xDD``.
Lesson 151 of 356 · tests/chapter_01_cpu/test_151_CMP_absolute_x.py
Why this step exists
Absolute,X lets CMP compare A with indexed tables outside zero page while keeping address calculation separate from comparison semantics.
In this step, lessons 146-150 already provide `cmp, its opcode import, and the earlier CMP modes. Add the following to emulator/cpu/opcodes.py`:
def cmp_absolute_x(cpu: CPU):
addr = absolute_x(cpu)
value = cpu.bus.read(addr)
cmp(cpu, value)
OPCODE_TABLE = {
...
0xDD: cmp_absolute_x,
}`emulator/cpu/addressing_modes.py::absolute_x` fetches the little-endian base word and adds X; the handler reads that effective address and compares its value with A. Only C/Z/N change; A, X, memory, and Overflow are invariant, and opcode plus word advances PC three bytes.
Misconception: X indexes the decoded address, not either operand byte, and is not itself modified. Out of scope: CMP absolute,Y and indirect modes (lessons 152-154), plus CPX/CPY work in lessons 155-162.
Run this lesson
uv run pytest tests/chapter_01_cpu/test_151_CMP_absolute_x.py -v