117. And immediate
expose AND immediate as opcode ``0x29``.
Lesson 117 of 356 · tests/chapter_01_cpu/test_117_AND_immediate.py
In this step, use the instruction from lesson 116 and add its import, immediate handler, and opcode-table entry in `emulator/cpu/opcodes.py`.
Why this step exists
The immediate form makes the newly introduced AND primitive executable with a literal operand and establishes its first opcode-table integration.
Suggested implementation
from emulator.cpu.instructions import (..., and_a)
def and_immediate(cpu: CPU):
and_a(cpu, immediate(cpu))
OPCODE_TABLE = {
...
0x29: and_immediate,
}`emulator/cpu/addressing_modes.py::immediate calls CPU.fetch_byte and returns that byte as the value. and_a` stores A & value and changes only Z/N, so Carry and Overflow remain invariant; the opcode and operand advance PC by two bytes and memory is not modified.
Misconception: immediate mode does not return an address, so an extra `cpu.bus.read` would interpret the literal as a pointer. Out of scope: zero-page through indirect,Y AND handlers (lessons 118-124), and the ORA/EOR/ BIT work in lessons 125-145.
Run this lesson
uv run pytest tests/chapter_01_cpu/test_117_AND_immediate.py -v