LDA - Load Data Accumulator Command
This is the command you use to load a value into the data accumulator.
The data accumulator is a temporary storage location where you can compare and manipulate a piece of data.
Every task has its own accumulator.
This is a single byte memory location where a value can be temporarily stored when the task has to use it.
The accumulator is only a single byte so if you attempt to load a value greater than 255 it gets divided by 255 and the remainder is what gets loaded.
The LDA command can also be modified by the X register to load from an array.
| Using the CMP Command doesn’t destroy the accumulator so you can do it repetitively without reloading. |
Syntax
LDA x
Where "x" is the value or memory location you want to put into the accumulator. You may use a raw value (hex or decimal), tilde memory, tasking port, or persistent memory. You can even load from the message buffer using the @ symbol to specify which byte to load from.
It can be any value from 0-255.
| When loading from the @buffer you are limited to the first 16 bytes. (@15). |
LDA Label,x
Where "Label" is the Label you want it to load from offset by the value in the X register.
This technique is used to dynamically use a value from an array. Typically you will use the Send2() command after the Label because it is not limited to valid DyNet packets.
|
The Send2() command is 5 bytes long so it requires an offset of 5 to get past the label. You must load a value of 5 into the X register to get the first value in the array. An array does not need to be in a task. It can be before or in between tasks in the task editor. |
-
LDA #x - Loads a fixed value (decimal or hex)
-
LDA ~x - Loads from a tilde memory
-
LDA $x - Loads from a persistent memory
-
LDA ^x - Loads from a task port
-
LDA @x - Loads from a the memory buffer
-
TXA Command - Transfers X register to the accumulator
-
SWAP Command - Swaps X register with the accumulator
-
LDA Label,x - Loads from an array offset by the X register
Examples
Example 1
Basic ways of loading to the accumulator.
{
LDA #11 //Loads the decimal value of 11 into the accumulator.
LDA #0x0A //Loads the Hex value of 10 into the accumulator.
LDA ~2 //Loads whatever is stored in tilde memory ~2 into the accumulator.
LDA ^35,1 //Lux level Hi byte into the accumulator.
LDA ^10,0 //Loads keyboard port. (check what button was pressed)
LDA $10 //Load value from persistent memory location 10.
LDA $Area4_State //Load value from persistent memory location named "Area4_State".
LDA #PrimaryArea //Load value of the constant named "PrimaryArea".
LDA @3 //Loads the opcode from the message buffer into the accumulator.
}
Example 2
Loading from the buffer.
{
Name="Temp Set Point Value Grabber"
start(0x1C,AreaTemp,0x0D,0x48,x,x,0xFF) //Start on Set Temp message.
LDA @4 //Grab the 5th byte of the last message. (the whole temp in C)
STA ~10 //Store it into memory.
...
}
Example 3
Loading from an array using the X register.
PresetOpcodeArray: Send2(0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D)
{
...
LDA ~15 //Load the preset number we want to send
ADD #5 //Add 5. Arrays have an index of 5 if using Send2
SWAP //Swap it into the X Register
LDA PresetOpcodeArray,x //Grab the correct opcode from the array
STA ~3 //Store it into the opcode byte of the classic preset message.
TX ~0,2,7 //Send the preset message
Null
...
}
Example 4
Excerpt from a task that loads from an array using the X register to convert from percentage to the hex value for a D2 channel level message.
ChannelLevelArray:Send2(0,1,4,6,9,12,14,17,19,22,24,27,29,32,34,37,39,42,44,47,49,52,54,57,59,62,65,67,70,72,75,77,80,82,85,87,90,92,95,97,100,103,105,108,110,113,115,118,121,123,126,129,132,134,136,139,141,144,146,149,151,154,156,159,161,164,167,169,172,174,177,179,182,184,187,189,192,195,197,200,202,205,207,210,212,215,217,220,222,225,228,230,233,235,238,240,243,245,248,250,254)
{
...
LOAD_LEVEL:
LDA iLight_RX_Data3 //Load the iLight level byte as 0-100%
ADD #5 //Add #5 to offset the array start
SWAP //Swap to x reg
LDA ChannelLevelArray,x //Grab the right percentage from the array
STA DyNet2_Level_Send_Byte //Store into the DyNet level byte
...
}