204. Tsx implied

wire implied TSX opcode $BA.

Lesson 204 of 356 · tests/chapter_01_cpu/test_204_TSX_implied.py

Why this step exists

In this step, the targets are `emulator/cpu/opcodes.py's instruction import and OPCODE_TABLE; emulator/cpu/instructions.py::tsx is supplied by step 203. This transition exposes TSX to emulator/cpu/cpu.py::CPU.step`.

Suggested implementation

from emulator.cpu.instructions import tsx  # add to the existing import

OPCODE_TABLE = {
    # existing entries
    0xBA: tsx,
}

Invariant: $BA is a one-byte implied instruction. Opcode fetch advances PC once, then `tsx(cpu)` copies S to X, updates only Zero/Negative, and leaves S unchanged. The common misconception is to fetch an operand byte or to omit the flag behavior because the addressing mode is implied.

Out of scope: Decimal-flag helpers and flag-control instructions begin at step 205; cycle accounting and later CPU facilities are unchanged here.

Run this lesson

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