165. Instruction bcs

implement Branch if Carry Set behavior.

Lesson 165 of 356 · tests/chapter_01_cpu/test_165_instruction_bcs.py

Why this step exists

The addressing layer has already consumed and signed the operand, so BCS only selects on Carry and applies the displacement to the next-instruction PC.

In this step, after BCC in lesson 164, add exactly

`emulator/cpu/instructions.py::bcs`::

def bcs(cpu: CPU, offset: int):
    if cpu.flags.get_carry_flag():
        cpu.pc = (cpu.pc + offset) & 0xFFFF

Masking makes both overflow and underflow wrap to 16 bits.

Invariants: Carry set takes the branch; Carry clear leaves PC unchanged. No status flag, other register, or memory changes. Misconception: BCS does not set Carry and does not branch when Carry is clear; it merely reads that flag.

Out of scope: subsequent branch instruction functions are lessons 166-171; all branch opcode imports, handlers, and table entries are lessons 172-179.

Run this lesson

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