STA - Store From the Accumulator Command

This command will copy whatever value is currently in the accumulator into the specified memory location or port. You can store either decimal or hex values.
The STA command can also be modified by the X register to dynamically store to a memory location.
This is very similar to the STX command but stores the accumulator value instead of the X register.

Using the STA command doesn’t destroy the accumulator so you can do it repetitively without reloading.

Syntax

Basic Use
STA y
Where "y" is the memory location or port you want to store the value from the accumulator into. You may use a tilde memory, task port, or persistent memory.
It can be any value from 0-255.

Advanced Use
STA y,x
Where "y" is the memory you want it to use as an origin to offset by the value in the X register.
Ex. If you have a value of #5 in the X register and STA ~0,x it will store to ~5 instead.

Ways you can store from the accumulator
  • STA ~y - Loads from a tilde memory

  • STA $y - Loads from a persistent memory

  • STA ^y - Loads from a task port

  • STA y,x - Loads from a memory location offset by the X register

Examples

Example 1

Basic ways to store values.

{
LDA #0x01           //Loads the hex value of 0x01 into the accumulator.
STA ~1              //Store that value into ~1 memory location.


LDA ~2              //Loads the value from ~2 into the accumulator.
STA ~12             //Store that value into ~12 memory location.


LDA #15             //Loads the decimal value of 15 (hex 0x0F) into the accumulator.
STA ~1              //Store that value into ~1 memory location.


LDA #StartValue     //Loads the value of the "StartValue" constant into the accumulator.
STA ~4              //Store that value into ~4 memory location.


LDA #3              //Loads the value of 3 into the accumulator.
STA $22             //Store that value into $22 persistent memory location.

LDA #0x03           //Loads the value of 3 into the accumulator.
STA $CurrentPreset  //Stores it into the persistent memory named "CurrentPreset".

LDA #0              //Load a value of 0 into the Accumulator
STA ^18,0           //Store to the LED Port (18,0) to 0. Turning LED’s 1-8 off
}

Example 2

Using the X register to offset the memory we store to.

#const AreaTracker ~0   //The origin for tracking what preset and area is in.
{
Start(0x1c,x,x,0x65,x,x,0xFF)   //Start off any linear preset.
LDX @1                          //Load the area into the X register
LDA @2                          //Load the preset into the accumulator
STA AreaTracker,x               //Store the preset value into the tilde memory with the same number as the area.
}