TAX - Transfer Accumulator to X Register Command
TAX - Transfers the accumulator value to the X register destroying the contents of the X register.
You can use this to temporarily store a value in the X register but a tilde memory works just as well.
The SWAP command often does this just as well.
This is the opposite of the TXA command.
Syntax
TAX
Notice that there is no argument attached to this command. It simply copies the accumulator value to the X register.
Examples
Example 1
This example uses the TAX command to load the X register for use in an array.
PresetOpcodeArray: Send2(0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D)
{
...
LDA ~15 //Load the preset number we want to send
ADD #4 //Add 4. Arrays have an index of 4
TAX //Move 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 2
This example moves a value into the X register and then moves it back later.
{
Start(0x1c,10,x,x,x,x,0x01) //Trigger on all 1c messages for area 10
Copy @0,~0,7 //When we see a message we copy the first 7 pieces of data into the memory
LDA ~3 //Load the opcode (Preset)
TAX //Move the preset into the X Reg so we can use the accumulator for something else but retain this for later.
LDA $2 //Load if the panel is locked which you stored into persistent memory 2.
CMP #1 //Is it "Unlocked"?
BRZ UpdateScene //Branch to the label "UpdateScene".
Null //If not unlocked end.
UpdateScene:
TXA //Move the preset back into the accumulator.
CMP #0x03 //Is it preset 4 "off"?
BRZ LightsOn //If so toggle the lights on.
Preset(A=10,P=4,J=0x02)//If not toggle them off.
Null
LightsOn:
Preset(A=10,P=1,J=0x02) //If not toggle them on.
Null
}