176. Bpl relative
connect BPL to its relative opcode.
Lesson 176 of 356 · tests/chapter_01_cpu/test_176_BPL_relative.py
Prerequisite: step 175 wired BNE. In this step, add the following to `emulator/cpu/opcodes.py`:
from emulator.cpu.instructions import bpl
def bpl_relative(cpu: CPU):
offset = relative(cpu)
bpl(cpu, offset)
OPCODE_TABLE[0x10] = bpl_relativeFold the import and entry into the existing grouped import and table literal.
Why this step exists
`relative consumes the operand and step 168's instructions.bpl` interprets "plus" as Negative clear before changing PC.
Invariants: `0x10` maps to the one-argument handler; both outcomes consume the signed operand; Negative clear branches from post-operand PC and Negative set does not. Flags and memory remain unchanged. Misconception: BPL does not test whether the offset or PC is positive; it tests only the Negative flag.
Out of scope: BMI/BVC/BVS opcode wiring is introduced by steps 177-179, and indirect JMP addressing is step 180.
Run this lesson
uv run pytest tests/chapter_01_cpu/test_176_BPL_relative.py -v