162. Cpy absolute
add CPY absolute opcode ``0xCC``.
Lesson 162 of 356 · tests/chapter_01_cpu/test_162_CPY_absolute.py
Why this step exists
Absolute CPY compares Y with a byte anywhere in CPU memory and verifies the two-byte operand is decoded as a little-endian address.
In this step, after lessons 159-161 provide `cpy and its immediate and zero-page handlers, add exactly the following to emulator/cpu/opcodes.py`:
def cpy_absolute(cpu: CPU):
addr = absolute(cpu)
value = cpu.bus.read(addr)
cpy(cpu, value)
OPCODE_TABLE = {
...
0xCC: cpy_absolute,
}`emulator/cpu/addressing_modes.py::absolute consumes a little- endian address through CPU.fetch_word; CC 00 02 therefore compares Y with the byte read from $0200 via instructions.cpy`.
Invariants: Y and memory are unchanged; only C/Z/N change, and opcode plus the two-byte operand advances PC by three bytes. Misconception: `00 02 is not the literal value 0x0002` to compare and is not a big-endian address.
Out of scope: relative addressing and branches begin at lesson 163.
Run this lesson
uv run pytest tests/chapter_01_cpu/test_162_CPY_absolute.py -v