CMP — Compare

Description
Section titled “Description”CMP (Compare) is true when its expression is true. One instruction holds a whole condition written out as text: Temp > 60 AND Level < 50, (Flags AND 12) == 12, ABS(Actual - Target) < 2. It is the condition-side twin of CPT, using the same operators and functions, and like every compare instruction it writes nothing. Use CMP when a test needs more than two operands, when it needs arithmetic before the comparison, or when it needs a bit mask. The classic masked compare, MEQ in RSLogix 500, is a CMP with AND and ==; LadderIDE has no separate MEQ. For a plain two-value test, EQU, GRT and friends read better on the rung.
Operands
Section titled “Operands”| Operand | Type | Format | Valid Range | Required | Description |
|---|---|---|---|---|---|
| Expression | Text | Tags, numbers, operators, functions, parentheses | Must not be empty | Yes | The condition. Non-zero is true, zero is false. |
Vocabulary:
| Kind | Accepted | Notes |
|---|---|---|
| Tags | Temp, TMR[0].ACC, Speeds[3], Status.3 |
Any numeric tag, member, element or INT/DINT bit. STRING tags cannot be used in an expression. |
| Numbers | 25, -3, 72.5, 0x1F |
Hexadecimal for masks. |
| Arithmetic | + - * | / |
| is the SLC divide, / also divides. No **; use XPY(base, exp). |
| Comparison | < > <= >= == != |
Equality is ==, never a single =. |
| Bit operators | AND OR XOR NOT |
Bitwise, on whole numbers. Because a comparison yields 0 or 1, AND and OR also combine comparisons. |
| Functions | SQR ABS SIN COS TAN ASN ACS ATN LN LOG EXP DEG RAD XPY TRN |
As in CPT. TRN truncates to a whole number. |
| Grouping | ( ) |
Use them freely. |
Comparisons bind tighter than AND/OR/XOR, so Temp > 60 AND Level < 50 needs no parentheses; add them anyway when the expression is long.
Scan Behavior
Section titled “Scan Behavior”Prescan
Section titled “Prescan”No state. Evaluates from the current values on the first scan.
Rung-condition-in is false
Section titled “Rung-condition-in is false”The instruction does not pass continuity. The block still colours by its own result on the canvas.
Rung-condition-in is true
Section titled “Rung-condition-in is true”The expression is evaluated with the current tag values. A non-zero result conducts; zero does not. An empty expression is always false; a blank condition never closes a rung.
Postscan
Section titled “Postscan”Nothing.
Example
Section titled “Example”Scenario: A batch may start when the jacket is hot enough and the vessel is not too full. Two tests, one instruction.
Tags:
Temp— Jacket temperature, REALLevel— Vessel level, INT (percent)Ready— Ready to start, BOOL
Rung 1:
—[CMP Temp>60 AND Level<50]———(OTE Ready)———Scan 1 — Temp = 72, Level = 65. The temperature passes but the level does not: 1 AND 0 is 0, the block is dark, Ready = 0. The face shows the expression as typed (spaces around the operators are optional) and colours by its result; the operand values are not painted on the block, so watch them in the Tag Browser.

Scan 2 — Level = 30. Both tests pass: 1 AND 1 is 1, the block lights, Ready = 1.

Masked compare (the MEQ role)
Section titled “Masked compare (the MEQ role)”To test some bits of a word and ignore the rest, AND the word with a mask and compare the result with the pattern you want. (Flags AND 12) == 12 is true when bits 3 and 2 are both set, whatever the other bits are doing.
CMP — (Flags AND 12) == 12 test that bits 3 and 2 are both set
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0Flags 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 = 45Mask 12 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0Flags AND 12 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 = 12 → 12 == 12, TRUE
Flags 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 = 41Flags AND 12 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 = 8 → 8 == 12, FALSEWrite the mask in hexadecimal when it is wide: (Status AND 0x00F0) == 0x0030. To ask “is any of these bits set” compare with != 0 instead: (Flags AND 12) != 0.
See Also
Section titled “See Also”- CPT — Compute (the same expression language, writing a result instead of gating the rung)
- EQU / GRT — the simple two-operand tests
- LIM — Limit Test (a band test without an expression)
- AND — Bitwise AND (the same masking as an output instruction)
- Compare Instructions — Category index
NOT is a bit complement, not a logical “not”. NOT (Temp > 60) flips every bit of the 0 or 1, giving −1 or −2, both non-zero, so the test is always true. To negate a comparison, turn the operator round: Temp <= 60. Use NOT on masks, where it means what it says.
| divides. It is the SLC 500 divide symbol, kept for people who learned it there. OR is the keyword, never |.
Division is floating point. Every | or / in an expression divides as a REAL whatever the operand types: Count | 2 > 3 is true for a Count of 7, because 3.5 is greater than 3. Use TRN when a whole-number quotient is wanted.
Reserved names. Tags cannot be named after a function or keyword (Log, Exp, And), so an expression can never confuse the two. The Tag Creator refuses such names.
Type of the result. The expression is evaluated as a number and the rung takes “non-zero”. Temp alone is therefore a valid expression, true whenever Temp is not 0.
Applies to LadderIDE >=1.2.2 · Last reviewed 2026-09-11 · Screenshots verified 2026-09-11