147. Cmp immediate

add CMP immediate opcode ``0xC9``.

Lesson 147 of 356 · tests/chapter_01_cpu/test_147_CMP_immediate.py

Why this step exists

The immediate form first exposes CMP through CPU execution, comparing A with a literal byte while leaving all comparison flag logic in the shared primitive.

In this step, lesson 146 already adds `cmp. As CMP's first opcode lesson, add its import and exactly the following handler/table entry in emulator/cpu/opcodes.py`:

from emulator.cpu.instructions import (..., cmp)

def cmp_immediate(cpu: CPU):
    cmp(cpu, immediate(cpu))

OPCODE_TABLE = {
    ...
    0xC9: cmp_immediate,
}

`addressing_modes.immediate` returns the fetched operand value directly, so there is no data-memory read. C/Z/N may change; A, Overflow, X, Y, and memory are invariant; opcode plus operand advances PC two bytes.

Misconception: immediate CMP does not treat its operand as an address or store the subtraction. Out of scope: CMP memory modes are lessons 148-154; CPX and CPY remain later lessons.

Run this lesson

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