CMPX - Compare the X Register Command
The CMPX command will compare the value currently stored in the X register with the argument.
The argument can be either a defined value (decimal or hex) such as #10 or #0x0a, or it can be a reference to a port or memory location.
The result of the comparison is used to make decisions in the task by setting/clearing the zero, carry, and minus flags.
Syntax
Basic Use
CMPX x
Where x is the value or memory you want to compare to the X register.
The CMP comparison subtracts the value of its argument from the value in the X register.
While the result of the comparison is stored in the devices’s memory it does not change the value in the X register or accumulator.
This comparison value is used for branching commands. (BRZ, BNE, BCC, BPL, BMI, BRC)
Comparison |
Zero Flag |
Carry Flag |
Minus Flag |
Equal |
Set |
Cleared |
Cleared |
ACC Greater Than |
Cleared |
Cleared |
Set if difference is greater than 128 |
ACC Less Than |
Cleared |
Set |
Set |
Advanced Use
CMPX Label,x
Where "Label" is the Label you want it to compare to offset by the value in the X register. As this compares the value in the X register to a value in an array offset by the same X register value it is not clear what a valid use case would be.
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 ways of using the CMPX command.
{
CMPX #11 //Compares the decimal value of 11 to the X register.
CMPX #0x0A //Compares the Hex value of 10 to the X register.
CMPX ~2 //Compares whatever is stored in tilde memory ~2 to the X register.
CMPX ^35,1 //Compares lux level Hi byte to the X register.
CMPX ^10,0 //Compares keyboard port to the X register.
CMPX $10 //Compares value from persistent memory location 10 to the X register.
CMPX $Area4_State //Compares value from persistent memory location named "Area4_State" to the X register.
CMPX #PrimaryArea //Compares value of the constant named "PrimaryArea" to the X register.
CMPX @3 //Compares the opcode from the message buffer to the X register.
}
Example 2
This example shows how you can use the X register as a second accumulator.
{
...
DimDownLoop:
LDA ~15 //Load what Bank we are in.
CMP #0x06 //If we are already at 0% we aren't getting any Dimmer.
BRZ DimDownEnd
CMP #0x05
BRZ Down10
BRA Skip
Down10:
LDX #DimToOFF //Load our Dim to off setting. 0=no, 1=yes. We use the X Reg so the Accululator can hold bank.
CMPX #0x00 //Is it a no?
BRZ DimDownEnd //If so end. If not continue.
Skip:
Inc //Increase it by 1.
STA ~15 //Store the new value back into the message buffer bank byte.
Tx ~10,2,7 //Then we send it out onto the network.
Delay(RampDelay)
BRA DimDownLoop
DimDownEnd:
Null
...
}