092. Asl zero page x

Add ASL Zero Page,X.

Lesson 92 of 356 · tests/chapter_01_cpu/test_092_ASL_zero_page_x.py

In this step, extend the Zero Page form from Test 091 with X indexing.

File and symbols

emulator/cpu/opcodes.py: asl_zero_page_x, OPCODE_TABLE[0x16]

Why this step exists

After Test 091 wired plain zero-page ASL, this transition reuses the established zero_page_x resolver so indexing and zero-page wrap remain addressing concerns.

Suggested implementation for this step

# emulator/cpu/opcodes.py
def asl_zero_page_x(cpu: CPU):
    addr = zero_page_x(cpu)
    asl(cpu, addr)

OPCODE_TABLE = {
    # existing entries unchanged
    0x16: asl_zero_page_x,
}

Important invariants

  • the effective address is (operand + cpu.x) & 0xFF
  • one operand byte is consumed, so PC advances by two including the opcode
  • asl owns the memory write and Carry, Zero, and Negative updates
  • indexing changes the destination, not the value passed to asl

Common misconception

Zero Page,X does not spill into page one: base 0xFE plus X=0x03 targets $0001.

Out of scope

  • ASL Absolute and Absolute,X in Tests 093-094
  • changing zero_page_x or asl
  • cycle timing

Run this lesson

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