An expression is a construct which is composed of operators and operands. The table below describes the list of operators and their priority.
Operators
| Operation | Symbols | Priority |
|---|---|---|
| Brackets | () | 1 |
| Parameter list of the function | FUNCTION_NAME(Param1, Param2, …) | 2 |
| Index | ** | 2 |
| Singular Operator (Code) | +, – | 3 |
| Complement | NOT | 3 |
| Multiplication | * | 4 |
| Division | / | 4 |
| Modular | MOD | 4 |
| Addition | + | 5 |
| Subtraction | – | 5 |
| Comparison | <, >, <=, >= | 6 |
| Equality | = | 7 |
| Inequality | <> | 7 |
| Logical Product | &, AND | 8 |
| Exclusive OR | XOR | 9 |
| Logical Sum | OR | 10 |
The operator with the higher priority will be operated first, and the operator with the next priority will be operated after. (This procedure will repeat until the calculation ends).
When operators with the same priority are used, the calculation is operated from left to right.
Arithmetic Operators
+ Operator
- The + operator adds the values on the left and right side of the operator.
- Format: Expression 1 + Expression
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Example | Result |
|---|---|
| DW500 := DW00 + 10; | D500 = D00 + 10 |
| DW00 := 20; DW01 := 30; DW10 := DW00 + DW01; | D10 = 50 |
– Operator
- The – operator subtracts the values on the left and right side of the operator.
- Format: Expression 1 – Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Example | Result |
|---|---|
| DW500 := 20 – 10; | D500 = 10 |
| DW00 := 30; DW01 := 20; DW10 := DW00 – DW01; | D10 =10 |
* Operator
- The * operator multiplies the values on the left and right side of the operator.
- Format: Expression 1 * Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators tables can be used.
| Example | Result |
|---|---|
| DW00 := 3; DW01 := 2; DW10 := DW00 * DW01; | D10 = 6 |
/ Operator
- The / operator divides the values on the left and right side of the operator.
- Format: Expression 1 / Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Example | Result |
|---|---|
| DW00 := 10; DW01 := 2; DW10 := DW00 / DW01; | D10 = 5 |
Dividing integers outputs the resulting integer. For example, DW10 := 3 / 2 results in D10 = 1.
MOD Operator
- The MOD operator divides the values on the left and right side of the operator and save the remainder.
- Format: Expression 1 + Expression 2
- Expression 1 must be positive
- Expression 2 CANNOT be 0.
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Example | Result |
|---|---|
| DW00 := 10; DW01 := 3; DW10 := DW00 MOD DW01; | D10 = 1 (10/3 = 1) |
** Operator
- The ** operator multiplies the values on the left side of the operator to the power of the value on the right side of the value.
- Format: Expression 1 ** Expression 2
- Expression1Expression2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Example | Result |
|---|---|
| DW00 := 10; DW01 := 3; DW10 := DW00 ** DW01; | D10 = 1,000 (103 = 1,000) |
Comparison Operators
= Operators
- The = operator compares if two expressions are equal.
- Format: Expression 1 = Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Expression 1 | Expression | Result |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
| Example | Result |
|---|---|
| IF MX00 = 1 THEN YX2A := 1; END_IF; | IF M0.0 = 1, then Y2.A = 1 |
<> Operators
- The < > operator compares if two expressions are not equal.
- Format: Expression 1 ≠ Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Expression 1 | Expression 2 | Result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
| Example | Result |
|---|---|
| IF MX00 <> 1 THEN YX2A := 1; END_IF; | If M0.0 ≠ 1, then Y2.A = 1 |
< Operators
- The < operator compares if the value on the left side is less than the value on the right side.
- Format: Expression 1 < Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Expression 1 | Expression 2 | Result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
| Example | Result |
|---|---|
| While DW00 < 5 D0 DW00 := DW00 + 1; DW10 := DW10 + DW00; END_WHILE; | While D0 is less than 5, D0 = D0 +1 and D10 = D10 + D0 |
> Operators
- The > operator compares if the value on the left side is greater than the value on the right side.
- Format: Expression 1 > Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Expression 1 | Expression 2 | Result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
| Example | Result |
|---|---|
| WHILE DW00 < 10 DO IF DW00 > 5 THEN EXIT; END_IF; DW10 := DW10 + DW00; DW00 := DW00 + 1; END_WHILE; | While D0 is less than 10, D10 = D10 + D0 and D0 = D0 + 1. If D0 is greater than 5, exit the while loop |
<= Operators
- The <= operator compares if the value on the left side is less than or equal to the value on the right side.
- Format: Expression 1 ≤ Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Expression 1 | Expression 2 | Result |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
| Example | Result |
|---|---|
| WHILE DW00 <= 5 DO DW00 := DW00 + 1 DW10 := DW10 + DW00; END_WHILE; | While D0 is less than or equal to 5, D0 = D0 + 1 and D10 = D10 + D0 |
>= Operators
- The >= operator compares if the value on the left side is greater than or equal to the value on the right side.
- Format: Expression 1 ≥ Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Expression 1 | Expression 2 | Result |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
| Example | Result |
|---|---|
| IF DW00 = 0 THEN DW10 = 10; END_IF; WHILE DW10 >= 1 DO DW00 := DW00 + DW10; DW10 := DW10 – 1; END_WHILE; | If D0 = 0, then D10 = 10. While D10 is greater than or equal to 1, D0 = D0 + D10 and D10 = D10 – 1 |
Logical Operators
AND (&) Operator
- The AND or & operator compares the bits of two operands. If the correlated bits are both 1, the result bit is 1.
- Format: Expression 1 AND Expression 2 or Expression 1 & Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Expression 1 | Expression 2 | Result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
| Example | Result |
|---|---|
| MX00 := 1; MX01 := 0; MX10 := MX00 AND MX01; | M1.0 = 0 (M0.0 & M0.1 = 0) |
OR Operator
- The OR operator compares the bits of two operands. If the correlated bits are both 1, the result bit is 1.
- Format: Expression 1 OR Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Expression 1 | Expression 2 | Result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
| Example | Result |
|---|---|
| MX00 := 1; MX01 := 0; MX10 := MX00 OR MX01; | M1.0 = 1 (M0.0 OR M0.1 = 1) |
XOR Operator
- The XOR operator compares the bits of two operands. If one of the correlated bits are 1, the result bit is 1. If the correlated bits are both 1, the result is 0.
- Format: Expression 1 XOR Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
| Expression 1 | Expression 2 | Result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
| Example | Result |
|---|---|
| MX00 := 1; MX01 := 1; MX10 := MX00 XOR MX01; | M1.0 = 0 (M0.0 XOR M0.1 = 0) |
NOT Operator
- The NOT operator compares the bits of two operands. If the bit of the operand is 1, the result is 0. If the bit of the operand is 0, the result is 1.
- Format: Expression 1 XOR Expression 2
- In Expression 1 and Expression 2, a constant, PLC data register, and the expressions listed in the Operators table can be used.
Truth Table
| Expression 1 | Result |
|---|---|
| 0 | 1 |
| 1 | 0 |
| Example | Result |
|---|---|
| MX00 := NOT 0; | M0.0 = 1 |
