201. Instruction txs
implement the TXS operation.
Lesson 201 of 356 · tests/chapter_01_cpu/test_201_instruction_txs.py
Why this step exists
In this step, add `emulator/cpu/instructions.py::txs`. This operation is introduced now because stack transfers are the remaining stack-instruction behavior: X is copied into the stack-pointer byte without a memory access.
Suggested implementation
def txs(cpu: CPU):
cpu.s = cpu.xInvariants: X, P, PC, A, Y, and memory are unchanged; S remains the low-byte offset into the already-established $0100-$01FF stack page. A common misconception is to update Zero and Negative as other register transfers do; TXS changes no flags, including when X is $00 or has bit 7 set.
Out of scope: registering implied opcode $9A in `emulator/cpu/opcodes.py::OPCODE_TABLE` belongs to step 202; TSX and its opcode belong to steps 203-204. Do not add those later APIs here.
Run this lesson
uv run pytest tests/chapter_01_cpu/test_201_instruction_txs.py -v