084. Iny 指令
添加 INY 指令行为。
第 84 / 356 · tests/chapter_01_cpu/test_084_instruction_iny.py
在这一步中,仅添加 iny,先于测试 085 的操作码映射以及测试 086-087 的 DEY 工作。
生产代码位置与符号
emulator/cpu/instructions.py: `iny(cpu: CPU)`本步骤存在的原因
INY 独立于操作码解码地递增 Y 寄存器,并且必须在 Python 无界整数的情况下模拟一个 8 位寄存器。
实现建议
def iny(cpu: CPU):
result = cpu.y + 1
result_8 = result & 0xFF
# Set flags
cpu.flags.set_negative_flag((result_8 & 0b1000_0000) != 0)
cpu.flags.set_zero_flag(result_8 == 0)
cpu.y = result_8重要不变量
- Y 从 0xFF 回绕到 0x00
- Zero 和 Negative 由掩码后的结果计算得出
- Carry、Overflow、内存及其他寄存器保持不变
常见误解
Y 回绕时递增操作不会设置 Carry;INY 只更新 Z 和 N。
不在本步骤范围内
- 操作码 0xC8 的分发(测试 085)
- DEY 行为与分发(测试 086-087)
- 后续的 ASL 工作及周期计时
运行本课
uv run pytest tests/chapter_01_cpu/test_084_instruction_iny.py -v