158. Cpx absolute
add CPX absolute opcode ``0xEC``.
Lesson 158 of 356 · tests/chapter_01_cpu/test_158_CPX_absolute.py
Why this step exists
Absolute CPX extends the comparison to a byte anywhere in CPU memory while keeping little-endian address decoding outside the CPX primitive.
In this step, complete CPX by adding exactly the following to `emulator/cpu/opcodes.py`:
def cpx_absolute(cpu: CPU):
addr = absolute(cpu)
value = cpu.bus.read(addr)
cpx(cpu, value)
OPCODE_TABLE = {
...
0xEC: cpx_absolute,
}`emulator/cpu/addressing_modes.py::absolute obtains a little-endian word through CPU.fetch_word; EC 00 02 therefore compares X with the value at $0200`. Only C/Z/N change; X, memory, and Overflow are invariant, and opcode plus word advances PC three bytes.
Misconception: the operand word is an address, not a 16-bit compared value. Out of scope: the CPY instruction and its three opcodes (lessons 159-162).
Run this lesson
uv run pytest tests/chapter_01_cpu/test_158_CPX_absolute.py -v