LDX (LoaD X register)¶
X = [operand]
LDX (LoaD X register) is an instruction that loads a value from memory into the X register. The operand can be either an immediate value, a memory location specified by its address, or a memory location specified by an indexed indirect or indirect indexed address.
The result is stored in the X register, and the Zero and Negative flags are set based on the result.
Addressing Modes¶
Mode |
Syntax |
Bytes |
Cycles |
---|---|---|---|
LDX #const |
|
2 |
|
LDX zp |
|
3 |
|
ZeroPage+Y |
LDX zp,y |
|
4 |
LDX addr |
|
4 |
|
Absolute+Y |
LDX addr,y |
|
4-5 |
Flags Affected¶
N (Negative) – Set if the loaded value has the most significant bit set (i.e., is negative); otherwise, it is cleared.
Z (Zero) – Set if the loaded value is zero; otherwise, it is cleared.
Examples¶
Load a Constant into the X Register¶
LDX #10 ; load X with constant 10
Load a Value from a Memory Location¶
LDX $20 ; load X with the value at memory location $20
Load a Value from a Memory Location with an Offset¶
LDY #2 ; load Y with 2
LDX $10,Y ; load X with the value at memory location $12 ($10 + Y)
See Also¶
LDA (LoaD Accumulator)
STA (STore Accumulator)
LDY (LoaD Y register)