035. Ldx absolute y

Add LDX absolute,Y ($BE).

Lesson 35 of 356 · tests/chapter_01_cpu/test_035_LDX_absolute_y.py

File to update

emulator/cpu/opcodes.py

Locations

opcodes.ldx_absolute_y
opcodes.OPCODE_TABLE[$BE]

Why this step exists

This lesson completes the LDX opcode family available at this point by reusing the existing absolute,Y helper. As with the other memory forms, the handler resolves and reads the operand before passing its value to ldx.

Complete example implementation

# emulator/cpu/opcodes.py
def ldx_absolute_y(cpu: CPU):
    addr = absolute_y(cpu)
    value = cpu.bus.read(addr)
    ldx(cpu, value)


OPCODE_TABLE = {
    # Preserve existing entries.
    0xBE: ldx_absolute_y,
}

Important invariants

  • $BE maps to ldx_absolute_y
  • the little-endian base address is indexed with Y, not X
  • the byte at the indexed address is passed to ldx
  • two operand bytes are consumed, so the full instruction advances PC by three

Common misconception

Do not wrap absolute,Y within page $00; unlike zero-page,Y, its indexed address is a 16-bit result.

Out of scope

  • store-X and load-Y instructions
  • changes to absolute_y or ldx
  • cycle timing and page-cross penalties

Run this lesson

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