Carl
all lessons
The 6502, by doing Lesson 6 of 9

Tables and indexed addressing

X and Y aren't just counters — they're index registers. LDA table,X reads the X-th byte of a table. Lay out an animation as a list of bytes and step a pointer through it; the LEDs play whatever you wrote down.

6502 assembly indexed tables data

X and Y earn their name “index registers” here. LDA patt,X means “load the byte at address patt plus X.” Bump X and you walk along a list of bytes in memory. That one addressing mode is how the 6502 does arrays, strings, lookup tables — and animations.

.byte lays raw bytes into the program — data, not instructions. The label patt is just the address of the first one. The loop reads patt[0], patt[1], … to the LEDs, wraps, and repeats: the lights play back exactly the sequence you wrote.

CodeLab — Play a pattern from a table
6502 source — stores to VIA Port B ($B000 = 8 LEDs)
loading…
assembler
VIA Port B — 8 LEDs (bit 7 … 0)
CPU
disassembly

Assemble, then Run: the LEDs “fill up” left-to-right, then snap empty and refill — because that’s literally the byte list in patt. Change the numbers and you’ve authored a new animation, no logic touched. CPX #$08 (“compare X with 8”) sets the zero flag when X hits 8 so BNE knows when to wrap.

Try this: make patt a back-and-forth bounce ($01,$02,$04,$08,$10,$20,$40,$80) and grow CPX to match its length. The animation lives in the data now.

Next: stop wasting cycles in delay loops — let the VIA’s hardware timer set the pace.