157. Cpx zero page
add CPX zero-page opcode ``0xE4``.
Lesson 157 of 356 · tests/chapter_01_cpu/test_157_CPX_zero_page.py
Why this step exists
Zero-page CPX distinguishes a compact memory address from an immediate value and passes the fetched byte to the existing comparison primitive.
In this step, with `cpx and immediate mode already present, add to emulator/cpu/opcodes.py`:
def cpx_zero_page(cpu: CPU):
addr = zero_page(cpu)
value = cpu.bus.read(addr)
cpx(cpu, value)
OPCODE_TABLE = {
...
0xE4: cpx_zero_page,
}`emulator/cpu/addressing_modes.py::zero_page fetches the one-byte address; the handler must read that address before calling instructions.cpx`. Only C/Z/N change; X and memory remain invariant, and opcode plus operand advances PC two bytes.
Misconception: unlike immediate CPX, the operand byte names a memory location rather than the compared value. Out of scope: CPX absolute (158) and all CPY work (159-162).
Run this lesson
uv run pytest tests/chapter_01_cpu/test_157_CPX_zero_page.py -v