046. Ldy absolute x
Add LDY absolute,X ($BC).
Lesson 46 of 356 · tests/chapter_01_cpu/test_046_LDY_absolute_x.py
File to update
emulator/cpu/opcodes.pyLocations
opcodes imports of absolute_x and ldy
opcodes.ldy_absolute_x
opcodes.OPCODE_TABLE[$BC]Why this step exists
This lesson completes the LDY opcode family by reusing absolute,X address resolution, then reading the effective address and applying the existing ldy behavior.
Complete example implementation
# emulator/cpu/opcodes.py
from emulator.cpu.addressing_modes import absolute_x
from emulator.cpu.instructions import ldy
def ldy_absolute_x(cpu: CPU):
addr = absolute_x(cpu)
value = cpu.bus.read(addr)
ldy(cpu, value)
OPCODE_TABLE = {
# Preserve existing entries.
0xBC: ldy_absolute_x,
}Important invariants
- $BC maps to ldy_absolute_x and consumes two operand bytes
- X, not Y, is added to the decoded 16-bit base address
- the effective address is read before its value is passed to ldy
ldyupdates Zero and Negative from the loaded byte
Common misconception
LDY absolute,X does not index with the destination register Y; the encoding explicitly uses X.
Out of scope
- STY opcode handlers
- page-crossing cycle penalties
- changes to absolute_x
Run this lesson
uv run pytest tests/chapter_01_cpu/test_046_LDY_absolute_x.py -v