070. Sbc indirect y
Add SBC (Indirect),Y.
Lesson 70 of 356 · tests/chapter_01_cpu/test_070_SBC_indirect_y.py
File to update
emulator/cpu/opcodes.pySymbols to add/update
opcodes.sbc_indirect_y and OPCODE_TABLE[0xF1]Why this step exists
This final SBC addressing variant uses the existing indirect_y resolver to read a base pointer from zero page, add Y, and supply the target byte to sbc.
Complete example implementation
# emulator/cpu/opcodes.py
def sbc_indirect_y(cpu: CPU):
addr = indirect_y(cpu)
value = cpu.bus.read(addr)
sbc(cpu, value)
OPCODE_TABLE = {
# ... existing entries ...
0xF1: sbc_indirect_y,
}Important invariants
indirect_yreads the zero-page pointer before adding Y- the handler reads the byte at the final address exactly once
- the read value is passed to
sbc, which owns A and flag updates - executing the two-byte instruction advances PC by two bytes
Common misconception
(Indirect),Y does not add Y to the zero-page pointer location before dereferencing; that pre-indexing behavior belongs to (Indirect,X).
Out of scope
- later INC and other instruction families
- changes to indirect addressing or SBC arithmetic
- cycle timing and page-cross penalties
Run this lesson
uv run pytest tests/chapter_01_cpu/test_070_SBC_indirect_y.py -v