DEC - Decrement the Accumulator Command
Decrements the value in the accumulator by one and stores it to the accumulator.
This is useful for countdowns or tracking the number of loops a task has completed.
Same effect as a SUB 1 command.
If the current value in the accumulator is #0 then when the value is decremented the accumulator goes to #255 and the carry and minus flags is set. |
Syntax
DEC
Notice that there is no value or location attached to this command. It simply decreases the value in the accumulator by 1.
Examples
Example 1
This sequence executes a countdown in seconds set in the task template.
{
LDA #0 //Reset the counter.
STA ~1 //Store it.
Loop:
LDA ~1 //Load memory location ~1 into the accumulator.
CMP #TargetValue //Compares the value to a constant from the task template.
BRZ END //Branches when the count down is reached.
Delay(1) //Delay 1 second.
DEC //Decrease the value by 1.
STA ~1 //Store back into ~1.
BRA Loop
Null
END:
Preset(A=4,P=1)//Do the thing we were counting down to do.
Null
}
Example 2
This sequence delays a given message based on device box number to prevent packet collisions on startup.
{
LDA ^14,0 //Get Box number
Loop:
BRZ Request //If box number is zero branch
DEC //If not reduce it by 1
Delay(1) //Wait one sec to stagger responses
BRA Loop
Null
Request:
DyNet(1C,LightingArea,00,63,00,00,FF) //Request current preset.
Null
}