The LDA
(Load Accumulator) instruction is one of the most frequently used opcodes on the 6502 processor. It loads an 8-bit value into the A register, also known as the accumulator. This value can come from memory or be embedded directly in the instruction itself.
Understanding LDA is a great starting point for learning how the 6502 interacts with memory and how addressing modes work.
What LDA Does
At its core, LDA performs one simple task:
It loads a value into the accumulator (A).
But depending on the addressing mode, the source of that value can vary:
- A constant value (immediate)
- A memory location (zero page, absolute)
- A computed address (indexed, indirect)
Each variation has its own binary opcode and CPU cycle cost.
Supported Addressing Modes
Here are all the addressing modes that LDA supports:
Addressing Mode | Example | Opcode | Bytes | Cycles | Description |
Immediate | LDA #$10 | $A9 | 2 | 2 | Load a constant value |
Zero Page | LDA $00 | $A5 | 2 | 3 | Load from first 256 bytes |
Zero Page, X | LDA $10,X | $B5 | 2 | 4 | Add X to base zero-page address |
Absolute | LDA $1234 | $AD | 3 | 4 | Load from a full 16-bit address |
Absolute, X | LDA $1234,X | $BD | 3 | 4 (+1) | Add X to absolute address |
Absolute, Y | LDA $1234,Y | $B9 | 3 | 4 (+1) | Add Y to absolute address |
Indirect, X | LDA ($20,X) | $A1 | 2 | 6 | Add X, then dereference pointer |
Indirect, Y | LDA ($20),Y | $B1 | 2 | 5 (+1) | Dereference, then add Y |
Note: Modes marked with (+1) may require an extra cycle if a page boundary is crossed.
Flags Affected
Executing LDA updates two status flags:
- Zero Flag (Z): Set if the loaded value is 0
- Negative Flag (N): Set if the high bit (bit 7) of the value is set (i.e., if the value is negative in two’s complement)
No other flags are affected.
Example: Loading a Constant
LDA #$42
This loads the hexadecimal value $42 into the accumulator. The Z and N flags are updated accordingly.
Example: Reading from Memory
LDA $0400
Loads the value stored at address $0400—which happens to be the start of the C64’s screen memory—into A.
If used in a loop, this kind of instruction is ideal for reading and modifying blocks of memory.
Example: Using Indirect Addressing
LDA ($10),Y
This is a powerful form of pointer-based memory access. It allows you to store a base address at $10/$11, and then offset it with Y. This is often used for accessing tables or sprite data.
Common Pitfalls
- Forgetting that only Z and N flags are affected. If you’re branching based on carry or overflow after LDA, you’ll get misleading results.
- Not accounting for the extra cycle on page crossings in Absolute,X and Indirect,Y modes. This matters for cycle-accurate code like raster interrupts or real-time effects.
Summary
LDA is essential to nearly all 6502 programs. It’s how you get data into the accumulator to do something useful—whether that’s math, logic, display updates, or system calls.
Once you understand how LDA works across all addressing modes, you’ve unlocked a fundamental part of 6502 programming. The next steps? Explore its siblings LDX and LDY, and learn how the 6502 transfers and manipulates data across registers.