DECX - Decrement the X Register Command
Takes the value currently stored in the X register, decrements that value by one and stores the new value in the X register.
Syntax
DECX
Notice that there is no value or location attached to this command. It simply decreases the value in the X register by 1.
If the value in the X register is now #0 then the zero flag is set.
If the X register value is then decremented again it goes to #255 and the carry and minus flags are set and the zero flag is cleared.
Examples
Example 1
{
LDX #0x04 // Put the fixed hex value 0x04 into the X Register.
CMPX #0x03 // 0x04-0x03=1. Clears all flags
BRZ Label // Will not branch as Zero flag not set
DECX // Decrement the value in the X Register by one
CMPX #0x03 // 0x03-0x03=0. Sets the Zero flag.
BRZ Label // Will branch to label as Zero flag is now set.
}
Example 2
This sequence delays a given message based on device box number to prevent packet collisions on startup.
{
LDX ^14,0 //Get Box number
Loop:
BRZ Request //If box number is zero branch
DECX //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
}