Absolute + X Mode¶
Syntax¶
instruction absolute_address, X
Description¶
In the absolute-X addressing mode, the effective address is calculated by adding the contents of the X register to a 16-bit absolute address specified in the instruction. The result is the target address, which is used to operate on the memory location pointed to by this 16-bit address.
Example¶
Here’s an example using the LDA instruction in absolute-X addressing mode:
LDA $2000,X
Assume that the X register contains $04. The instruction will perform the following steps:
Fetch the low byte of the absolute address from $2000 ($00).
Fetch the high byte of the absolute address from $2001 ($20).
Combine the high and low bytes to form the absolute address: $2000.
Add the X register ($04) to the absolute address ($2000), resulting in the target address: $2004.
Load the value at memory location $2004 into the accumulator.
Timing¶
When the sum of the absolute address and the X register results in a carry from one memory page to the next, an additional clock cycle is required for the instruction. This is because the processor needs to fetch the high byte from the next page before the low byte. Be aware of this limitation when working with absolute-X addressing mode.
Use Cases¶
Absolute-X addressing mode is particularly useful for accessing elements in an array or a data structure using an index, where the starting address of the array or data structure is known.