liveBook · Manning

Memory mode

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

An addressing mode is an assembly-language rule that determines how an instruction identifies its operand or memory location.

A memory mode, also called an addressing mode, tells a 6502 instruction whether its operand is a literal value or a memory location, and how that location is found. Load instructions move a selected value into A, X, or Y; store instructions move a register value to the selected destination. section 3.3.1 section 3.3.2

Table 3.7 The available addressing modes (view table figure)

Mode

Description

Immediate

The actual numerical value is specified immediately after the statement.

Zero-page memory

The value is obtained from a location in zero-page memory using an 8-bit offset.

Absolute memory

The value is obtained from anywhere in memory using a 16-bit memory address.

Zero-page index with X or Y

The value is obtained from a location in zero-page memory by adding an 8-bit offset address to the value in either the X or Y index registers to get the final 8-bit offset.

Absolute memory indexed with X or Y

The value is obtained from a location anywhere in memory starting at a specified 16-bit memory address and adding the value in either the X or Y index to determine the final memory address to get the value from.

Zero-page indirect indexed with Y

The value is obtained from a location anywhere in memory starting at the base address stored in the specified 2 bytes of zero-page memory, and then the value in the Y register is added to that address to get the final address.

Zero-page Indexed indirect with X

The value is obtained from a location anywhere in memory starting at the base zero-page offset and adding the value in the X register to get the location in zero-page memory where the final address is specified in 2 bytes of memory.

Use this table as a quick map of the load forms before trying each syntax pattern. section 3.3.1

The main forms build from direct locations to calculated addresses:

  • Immediate mode uses a number written in the instruction. A leading # means “use this value,” as in lda #$05. section 3.3.1
  • Zero-page mode names an address from $00 through $FF; without #, lda $05 reads the value stored at location $05. section 3.3.1
  • Absolute mode supplies a full 16-bit address, such as lda $0300 or sta $0300. section 3.3.1 section 3.3.2
  • Indexed modes add X or Y to a zero-page or absolute base address, allowing one instruction pattern to reach a shifted location. section 3.3.1 section 3.3.2
  • Indirect indexed forms use two zero-page bytes as a base address, then apply an index register to reach the final location. section 3.3.1 section 3.3.2

Distinguishing a value from an address

First place $10 in A, then store it at zero-page address $05. `lda #$10` loads the literal $10; `sta $05` writes it to memory; `lda $05` reads that stored value back into A. The # character changes what $05 means to the assembler. section 3.3.1 section 3.3.2

For stores, the register is the source and memory is the destination. Store forms use zero-page, absolute, indexed, and indirect addressing to choose where A, X, or Y is written; the available form depends on the instruction and register. section 3.3.2

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

How deep it goes
Works through immediate, zero-page, absolute, indexed, and indirect forms with diagrams, listings, and simulator results.
Examples
Demonstrates loading and storing hexadecimal values at $05, $0300, indexed addresses, and indirect zero-page pointers.
What it assumes
Introduces registers, memory locations, hexadecimal values, and assembler syntax through small load and store examples.
What you can do after
Apply it via 6502 assembler syntax to load register values and store registers at direct or calculated memory locations.
How it connects
Connects registers, zero-page memory, absolute memory, index registers, load instructions, and store instructions.

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.