049. Sty 绝对寻址
添加 STY 绝对寻址($8C)。
第 49 / 356 · tests/chapter_01_cpu/test_049_STY_absolute.py
要更新的文件
emulator/cpu/opcodes.py位置
opcodes imports of absolute and sty
opcodes.sty_absolute
opcodes.OPCODE_TABLE[$8C]为什么需要这一步
绝对寻址的 STY 通过解码一个 16 位目标地址,并将该地址传递给已有的存储指令,完成了受支持的 STY 家族。
完整示例实现
# emulator/cpu/opcodes.py
from emulator.cpu.addressing_modes import absolute
from emulator.cpu.instructions import sty
def sty_absolute(cpu: CPU):
addr = absolute(cpu)
sty(cpu, addr)
OPCODE_TABLE = {
# Preserve existing entries.
0x8C: sty_absolute,
}重要不变量
- $8C 映射到 sty_absolute 并消耗两个操作数字节
- 小端操作数被解析为一个 16 位目标地址
- sty 通过总线把 Y 写入该地址
- 执行总共前进三个字节,标志位保持不变
常见误区
不要把从绝对地址读取到的值传给 sty;核心存储指令需要的是目标地址本身。
范围之外
- 转移指令及其操作码
- STY 的其他寻址模式
- 周期时序与写侧硬件效应
运行本课
uv run pytest tests/chapter_01_cpu/test_049_STY_absolute.py -v