204. Tsx 隐含寻址

接通隐含寻址 TSX 操作码 $BA。

204 / 356 · tests/chapter_01_cpu/test_204_TSX_implied.py

本步骤存在的原因

在本步骤中,目标是 `emulator/cpu/opcodes.py 的指令导入以及 OPCODE_TABLEemulator/cpu/instructions.py::tsx 由步骤 203 提供。这次变更使 TSX 可以通过 emulator/cpu/cpu.py::CPU.step` 暴露出来。

建议实现

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

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

不变式:$BA 是单字节隐含寻址指令。操作码取指使 PC 前进一次,随后 `tsx(cpu)` 将 S 复制到 X,仅更新 Zero/Negative,并保持 S 不变。常见的误解是取一个操作数字节,或者因为寻址模式是隐含寻址就省略标志行为。

范围之外:Decimal 标志辅助函数和标志控制指令从步骤 205 开始;周期计数以及后续的 CPU 功能在此处不作改动。

运行本课

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