174. Beq relative
connect BEQ to its relative opcode.
Lesson 174 of 356 · tests/chapter_01_cpu/test_174_BEQ_relative.py
Prerequisite: step 173 wired BCS. In this step, add the following to `emulator/cpu/opcodes.py`:
from emulator.cpu.instructions import beq
def beq_relative(cpu: CPU):
offset = relative(cpu)
beq(cpu, offset)
OPCODE_TABLE[0xF0] = beq_relativeThe import and mapping can be merged into the existing grouped structures.
Why this step exists
`relative supplies the signed, post-operand displacement and step 166's instructions.beq` branches when the existing Zero flag is set.
Invariants: `0xF0 dispatches to a one-argument handler and consumes its operand whether or not Zero is set; +5 from 0x8002 reaches 0x8007`. No flags or memory change. Misconception: BEQ does not compare values itself; it only observes Zero as established by an earlier operation.
Out of scope: BNE/BPL/BMI/BVC/BVS opcode wiring belongs to steps 175-179; indirect JMP addressing belongs to step 180.
Run this lesson
uv run pytest tests/chapter_01_cpu/test_174_BEQ_relative.py -v