LDX

From C64-Wiki
Jump to navigationJump to search

LDX (short for "LoaD X") is the mnemonic for a machine language instruction which retrieves a copy from the specified RAM or I/O address, and stores it in the X index register. The content of the memory location is not affected by the operation.

Addressing modes[edit]

Opcode Addressing
mode
Assembler
format
Length
in bytes
Number of
cycles
Dec Hex
162 A2 Immediate LDX #nn 2 2
174 AE Absolute LDX nnnn 3 4
190 BE Absolute,Y LDX nnnn,Y 3 4*
166 A6 Zeropage LDX nn 2 3
182 B6 Zeropage,Y LDX nn,Y 2 4

LDX supports the five addressing modes shown in the table at right. In the assembler formats listed, nn represents a single-byte (8-bit) figure, and nnnn is a two-byte (16-bit) address.
With some addressing forms (marked with an asterisk, *, in the "Number of cycles" column) the execution time for LDX depends on the circumstances: In cases where the indexing requires the CPU to "reach across" a page boundary from the base address, the execution time is 1 cycle longer than listed here.

CPU flags[edit]

LDX affects 2 of the CPU's status flags:

  • The negative status flag is set if the result is negative, i.e. has its most significant bit set.
  • The zero flag is set if the result is zero, or cleared if it is non-zero.