liveBook · Manning

Absolute indexed addressing mode

As explained in Classic Game Programming on the NES: Make your own retro video game

Absolute indexed addressing mode forms an operand address by adding an X or Y register value to a full memory address.

Absolute indexed addressing mode reaches memory by starting with a full 16-bit address and adding the current X or Y register value. The resulting address can be anywhere in memory. For example, with X set to $02, an operand written as $0300,X refers to $0302. section 3.3.1

Use this mode when a base address identifies the start of a memory area and an index register selects a position within it. The comma and register are part of the operand: $0300,X uses X; the mode can also use Y. This differs from zero-page indexed addressing, whose base is an 8-bit zero-page address. section 3.3.1

Load from an indexed address

Store $20 at $0302, set X to $02, then load from $0300,X. The processor calculates $0300 + $02, reads $0302, and places $20 in A. lda #$20 sta $0302 ldx #$02 lda $0300,x section 3.3.1

The same calculated address can supply an arithmetic operand. With $05 stored at $0302, A holding $10, and X holding $02, `adc $0300,x` reads $05 from $0302 and adds it to A, leaving $15 after carry is cleared. section 4.1.1

Store at an indexed address

For an indexed store, load A with the value to write, set the index, and use an absolute indexed destination. With A = $ee and X = $01, `sta $0300,x` writes $ee to $0301. Absolute indexed stores use A as the source register. section 3.3.2

Figure 3.12 Loading a value from memory using an index register

Follow the diagram from the base address and X value to the final memory location read by an indexed load. section 3.3.1

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Works through base-plus-index calculations and register results for loads, stores, and addition, without discussing processor internals.
Examples
Uses $0300 plus X to read $20 from $0302, write $ee to $0301, and add $05 into A.
What it assumes
Teaches indexed address calculation through explicit examples while using hexadecimal addresses and X or Y register values.
What you can do after
Apply it via 6502 assembly instructions to calculate indexed absolute addresses for memory reads, A-register stores, and addition.
How it connects
Connects absolute memory, X and Y index registers, zero-page indexed addressing, LDA, STA, and ADC.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.