Zero Page + X Mode

Syntax

instruction zero_page_address, X

Description

In the zero page-X addressing mode, the effective address is calculated by adding the contents of the X register to a zero page address specified in the instruction. The result is the target address, which is used to operate on the memory location pointed to by this target address.

Example

Here’s an example using the LDA instruction in zero page-X addressing mode:

LDA $10,X

Assume that the X register contains $04. The instruction will perform the following steps:

  1. Fetch the zero page address from the instruction ($10).

  2. Add the X register ($04) to the zero page address ($10), resulting in the target address: $14.

  3. Load the value at memory location $14 into the accumulator.

Use Cases

Zero page-X addressing mode is particularly useful for accessing elements in a small amount of memory, where the addresses are within the range of 0 to 255. This mode can be used for implementing efficient data structures such as arrays or lookup tables.

Bugs

One known bug with the 6502 zero page-X addressing mode is the “page crossing bug”. When the sum of the zero page address and the X register results in a carry from the zero page to the next memory page, the processor does not account for this carry. The effective address will be truncated to the range of 0 to 255. Be aware of this limitation when working with zero page-X addressing mode.

Comments