STX & STY – Store the X and Y Registers

After learning about STA, the instructions STX and STY follow naturally. They allow your program to store the contents of the X and Y index registers into memory.

If you’re managing data structures, looping through arrays, or setting up pointers, you’ll frequently want to move index values into memory — and that’s where these instructions come in.


What Do STX and STY Do?

Both instructions work exactly like STA, but they store the contents of the X or Y register instead of the accumulator.

They are purely output instructions — they move a value from a register into a given memory location.


Supported Addressing Modes

InstructionAddressing ModeExampleOpcodeBytesCycles
STXZero PageSTX $00$8623
Zero Page, YSTX $10,Y$9624
AbsoluteSTX $1234$8E34
STYZero PageSTY $00$8423
Zero Page, XSTY $10,X$9424
AbsoluteSTY $1234$8C34

💡 Notice:

  • STX supports Zero Page, Y
  • STY supports Zero Page, X
  • Neither supports absolute,X/Y or indirect modes
  • And like STA, no immediate mode

Flags Affected

None.
Just like STA, these instructions do not modify any status flags.


Example Usage

LDX #$FF
STX $D020      ; Set C64 border color using X register

LDY #$12
STY $C0        ; Store Y into zero page memory

LDX #$33
STX $0200,Y    ; Not valid! STX does not support (abs),Y

Indexed zero page example:

LDY #$02
LDX #$A0
STX $10,Y      ; Store X at address $12

Common Pitfalls

  • Misunderstanding addressing support.
    STX and STY are more limited than STA. If you need flexible addressing, move the value into A and use STA.
  • Trying to use STX/STY with absolute,X/Y.
    These modes are not valid with STX or STY.

Summary

STX and STY are crucial for saving index values to memory:

  • Store the contents of the X or Y register
  • Support zero page, indexed zero page, and absolute addressing
  • Don’t affect CPU flags
  • Great for setting up buffers, counters, and memory-mapped I/O

Combined with STA, these instructions give you full control over writing all main registers to memory.


Leave a Reply

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