LDX loads a source value into the 6502 X register. Like other load instructions, it begins with LD and names its target register with the final letter. The source can be a direct numerical value or a memory location. section 3.3.1
Choose the operand form by what the value represents:
- Use an immediate value when the number is written directly in the assembly listing: `LDX #$05` places 5 in X. The `#` means use the number itself. section 3.3.1
- Omit `#` to read a value from memory. For example, `LDX $05` loads X from zero-page location `$05`. section 3.3.1
Load X from zero-page memory
Store `$10` at `$05`, then run `LDX $05`. X receives `$10`; the operand identifies a memory location rather than the number 5. section 3.3.1
Table 3.7 The available addressing modes (view table figure)
| Mode |
Description |
|---|---|
| Immediate |
The actual numerical value is specified immediately after the statement. |
| Zero-page memory |
The value is obtained from a location in zero-page memory using an 8-bit offset. |
| Absolute memory |
The value is obtained from anywhere in memory using a 16-bit memory address. |
| Zero-page index with X or Y |
The value is obtained from a location in zero-page memory by adding an 8-bit offset address to the value in either the X or Y index registers to get the final 8-bit offset. |
| Absolute memory indexed with X or Y |
The value is obtained from a location anywhere in memory starting at a specified 16-bit memory address and adding the value in either the X or Y index to determine the final memory address to get the value from. |
| Zero-page indirect indexed with Y |
The value is obtained from a location anywhere in memory starting at the base address stored in the specified 2 bytes of zero-page memory, and then the value in the Y register is added to that address to get the final address. |
| Zero-page Indexed indirect with X |
The value is obtained from a location anywhere in memory starting at the base zero-page offset and adding the value in the X register to get the location in zero-page memory where the final address is specified in 2 bytes of memory. |
Use the addressing-mode table to distinguish direct values from zero-page and full-memory locations before selecting a load operand. section 3.3.1
