Indirect Addressing

From NES Hacker Wiki
Jump to: navigation, search

Indirect Addressing reads a memory location from a two-byte pointer. This particular addressing mode is used only by a special type of JMP. A pointer is first stored in memory, and read for the address rather than using an absolute position. There are two other indirect addressing modes, Pre-Indexed Indirect Addressing and Post-Indexed Indirect Addressing. Parenthesis are used to signify that the opcode is reading a pointer rather than an absolute value.


This example compares the usual absolute addressing of the JMP opcode to the Indirect Addressing mode.

0001:4C 04 00  JMP $0004       ; This example moves the program counter to $0004
                               ; and resumes execution. This is ABSOLUTE addressing.

0004:A9 05     LDA #$22        ; The first four lines create a pointer value of 
0006:85 00     STA $20         ; $1122 and store it into $0020-$0021.
0008:A9 20     LDA #$11
000A:85 01     STA $21
000C:6C 20 00  JMP ($0020)     ; Reads the location found in $0020-$0021, which 
                               ; we just set to $1122, then moves the program 
                               ; counter to the location. This is INDIRECT addressing.
                               ; Like all addresses, the pointer uses little-endian.


The following opcodes support indirect addressing: