169. Instruction bmi
implement Branch if Minus behavior.
Lesson 169 of 356 · tests/chapter_01_cpu/test_169_instruction_bmi.py
Why this step exists
"Minus" means the Negative flag from an earlier result is set, so BMI consumes that status without recomputing it.
In this step, add only this implementation
`emulator/cpu/instructions.py::bmi`::
def bmi(cpu: CPU, offset: int):
if cpu.flags.get_negative_flag():
cpu.pc = (cpu.pc + offset) & 0xFFFFBMI applies the already decoded signed displacement to the PC after its operand, masking the target to 16 bits.
Invariants: Negative set takes the branch and Negative clear leaves PC alone; flags, other registers, and memory are unchanged. Misconception: BMI does not inspect the sign of `offset` or perform arithmetic to establish Negative.
Out of scope: BVC/BVS are lessons 170-171. Imports into `emulator/cpu/opcodes.py`, relative handlers, and opcode table entries belong to lessons 172-179.
Run this lesson
uv run pytest tests/chapter_01_cpu/test_169_instruction_bmi.py -v