SUB - Subtract X from the Accumulator Command
Subtracts the argument from the current accumulator value and stores the result to the accumulator.
Syntax
Basic Use
SUB x
Where "x" is the value or memory location you want to subtract from the accumulator. You may use a raw value (hex or decimal), tilde memory, task port, or persistent memory.
Advanced Use
SUB 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. Not sure I can think of a valid use for this. If you use it let us know so we can update the examples.
| Arrays have an index of 4 so 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. |
Examples
Example 1
Basic uses.
{
LDA #0x02 //Put the fixed hex value 0x02 into the Accumulator
SUB #0x02 //Take 0x02 away from the value in the Accumulator which now contains the value 0. This will set the Zero flag
BRZ Label //The task will now branch to the label
LDA ~5 //Copy the value in tilde 5 to the Accumulator
SUB #10 //Subtract 10 from the value in the Accumulator
LDA ~5 //Copy the value in tilde 5 to the Accumulator
SUB #0x13 //Subtract the 0x13 (19) from the value in the Accumulator
LDA ~3 //Load the value from ~3 into the accumulator
SUB #5 //Subtract 5 from the value in the Accumulator
STA ~3 //Store the previous value minus 5 back into ~3
LDA ~3 //Load the value from ~3 into the accumulator
SUB $14 //Subtract the value in persistent memory 14.
STA ~3 //Store the new value back into ~3
LDA $15 //Load the value from persistent memory 15 into the accumulator
SUB ~14 //Subtract the value in tilde memory 14.
STA ~3 //Store the value into ~3
}