Pre-Indexed Indirect Addressing

From NES Hacker Wiki
Revision as of 02:37, 21 March 2015 by Novazero (talk | contribs) (Examples: Corrected example offset from 5 to 6 so that it indirect address would point to $0046 where value of $2005 is stored, hopefully avoid confusion for those learning)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Pre-Indexed Indirect Addressing is one of the three Indirect addressing modes of the 6502 processor. This mode accepts a zero-page address and adds the contents of the X-register to get an address. The address is expected to contain a 2-byte pointer to a memory address (ordered in little-endian). The indirection is indicated by parenthesis in assembly language.

This instruction is a three step process.

  1. Sum the operand and the X-register to get the address to read from.
  2. Read the 2-byte address.
  3. Return the value found in the address.

Keep in mind that this only operates on the zero page. The processor uses wrap-around addition to sum up the operand and the X-register. Thus, if you use an operand of $FF and an X-register of $10, the result is $0F, not $110 which you might expect.


This example loads the memory with a pointer and sets the X-register to read the value from the pointer's address.

0001:A9 05     LDA #$05        ; The first four lines create a pointer value of 
0003:85 00     STA $46         ; $2005 and store it into $0046-$0047.
0005:A9 20     LDA #$20
0007:85 01     STA $47
0009:A9 FF     LDA #$FF        ; Load A with #FF.
0011:8D 05 20  STA $2005       ; Store A into address $2005.
0014:A2 05     LDX #06         ; Load the X-register with #06.
0016:A1 40     LDA ($40, X)    ; Read the memory address located at $40 + X ($46).
                               ; The address there is $2005, which contains the value #FF,
                               ; So A will be loaded with #FF.


The following opcodes support pre-indexed indirect addressing: