STA – Store Accumulator


After learning how to load values into the accumulator using LDA, it’s time to store them back into memory. That’s exactly what the STA instruction does.

Where LDA is about input, STA is about output. It allows your 6502 program to write the value currently held in the accumulator (A) to a specific memory address.


What Does STA Do?

STA takes the value in the accumulator and writes it to a memory location. That location is specified using one of several addressing modes.

This is essential when you want to:

  • Update variables
  • Write to memory-mapped hardware (like screen RAM or I/O)
  • Store intermediate results for later use

Supported Addressing Modes

Unlike LDA, STA does not support the immediate mode — because you can’t store to a literal value.

Here are the valid modes:

Addressing ModeExampleOpcodeBytesCycles
Zero PageSTA $00$8523
Zero Page, XSTA $10,X$9524
AbsoluteSTA $1234$8D34
Absolute, XSTA $1234,X$9D35
Absolute, YSTA $1234,Y$9935
Indirect, XSTA ($20,X)$8126
Indirect, YSTA ($20),Y$9126

Flags Affected

None.
STA does not modify any status flags — not even Zero or Negative.

This makes sense: you’re writing data, not interpreting it.


Example Usage

LDA #$41       ; Load ASCII 'A' into accumulator
STA $0400      ; Write it to screen memory at $0400

LDA #$00
STA $D020      ; Set border color on the C64

Or, with indexed addressing:

LDX #$05
LDA #$FF
STA $0200,X    ; Store $FF at address $0205

Indirect addressing:

LDA #$3C
STA ($20),Y    ; Store A to address pointed to by $20 + Y

Common Pitfalls

  • Forgetting that STA doesn’t affect flags. If you plan to branch based on the accumulator value, test it before the STA.
  • Using STA #$44 — this is illegal. You can’t store to an immediate value!
  • Misusing indirect modes. STA ($20),Y looks up a pointer from zero page $20, adds Y, and stores the value.

Summary

STA is the simplest way to send data from your CPU into memory — and that includes writing to hardware like video, sound, or I/O chips.

Key takeaways:

  • Stores accumulator content into memory
  • Supports all basic addressing modes except immediate
  • Does not modify any flags
  • Essential for output, memory updates, and I/O access

With LDA and STA, you have the fundamental load-store mechanism of the 6502 down. Next up, we’ll explore storing other registers: STX and STY.


Leave a Reply

Your email address will not be published. Required fields are marked *