liveBook · Manning

Zero-page addressing mode

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

Zero-page addressing mode identifies an operand in the first 256 bytes of memory using a one-byte address.

Zero-page addressing mode names a memory operand in the first 256 bytes of memory. A direct zero-page address uses an 8-bit offset, unlike absolute addressing, which supplies a full 16-bit address. Use it when an instruction should read from or write to a location such as $06 rather than an address such as $0300. section 3.3.2 section 4.1.1

For stores, the register named by the instruction supplies the value and the zero-page location is the destination. `STA $06`, `STX $07`, and `STY $08` place the contents of A, X, and Y into those first-page locations. Inspecting memory after running the instructions verifies the bytes at $06 through $08. section 3.3.2

lda #$10
sta $06
ldx #$11
stx $07
ldy #$12
sty $08

This short listing shows direct zero-page stores from all three general registers: A to $06, X to $07, and Y to $08. section 3.3.2

Zero-page forms also work with index registers and indirect addresses:

  • Zero-page indexed addressing adds X or Y to an 8-bit starting address. For example, with X = $01, `STA $01,X` stores A at $02. section 3.3.2
  • Zero-page indirect indexed with Y uses two zero-page bytes as a base address, then adds Y to select the final destination or source address. section 3.3.2
  • Indexed indirect with X first uses X to select the zero-page location holding a two-byte base address. section 3.3.2

Add a value stored at $06

A zero-page address can be a source operand as well as a destination. Store $10 at $06, clear carry, load A with $04, then use `ADC $06`. The processor adds the byte from $06 to A, leaving A equal to $14. section 4.1.1

Listing 4.4 Adding a value from a zero-page address
Lda #$10
sta $06
clc
lda #$04
adc $06

The listing provides a complete run-ready example of storing a value at $06 and adding it to A with `ADC $06`. section 4.1.1

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

How deep it goes
Defines direct, indexed, and indirect zero-page forms through address calculations and runnable store and addition examples.
Examples
Demonstrates stores at $06–$08, indexed storage at $02, and adding the byte at $06 to A.
What you can do after
Apply it via 6502 store and ADC instructions to read or write values in the first 256 memory bytes.
How it connects
Connects zero-page addressing with absolute addressing, X and Y index registers, indirect addressing, stores, and addition with carry.

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.