099. Lsr zero page x

Add LSR Zero Page,X.

Lesson 99 of 356 · tests/chapter_01_cpu/test_099_LSR_zero_page_x.py

In this step, add X indexing to the Zero Page LSR form from Test 098.

File and symbols

emulator/cpu/opcodes.py: lsr_zero_page_x, OPCODE_TABLE[0x56]

Why this step exists

This transition adds indexed zero-page LSR by composing the existing zero_page_x resolver with memory lsr; it adds no new shift semantics.

Suggested implementation for this step

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

OPCODE_TABLE = {
    # existing entries unchanged
    0x56: lsr_zero_page_x,
}

Important invariants

  • effective address calculation wraps to eight bits within zero page
  • only one operand byte is consumed, so PC advances by two including the opcode
  • lsr owns the memory write and C/Z/N changes
  • X selects the destination and is not modified

Common misconception

Base 0xFE plus X=0x03 targets $0001, not $0101.

Out of scope

  • LSR Absolute and Absolute,X in Tests 100-101
  • changes to addressing or LSR behavior
  • cycle timing

Run this lesson

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