Pre-Indexed Indirect Addressing
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.
- Sum the operand and the X-register to get the address to read from.
- Read the 2-byte address.
- 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.
Examples
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.
Opcodes
The following opcodes support pre-indexed indirect addressing: