The IEC Operators • 289
Arithmetic Operators
Note:
If you define functions in your project with the names CheckDivByte,
CheckDivWord, CheckDivDWord and CheckDivReal, you can use them to check the value of the divisor if you use the operator DIV, for example to avoid a division by 0. The functions must have the above listed names. See in the following an example for the implementation of function CheckDivReal:
Operator DIV uses the output of function CheckDivReal as divisor. In a program like shown in the following example this avoids a division by 0, the divisor (d) is set from 0 to 1. So the result of the division is 799.
12.2.5MOD
Modulo Division of one variable by another of the types: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT. The result of this function will be the remainder of the division. This result will be a whole number.
WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32
290 • The IEC Operators
Example in IL:
LD |
9 |
MOD |
2 |
ST |
Var1 (* Result is 1 *) |
Example in ST:
var1 := 9 MOD 2;
Example in FBD:
Perform this function to find the internal index for a POU.
Example in ST:
var1 := INDEXOF(POU2);
12.2.7SIZEOF
Perform this function to determine the number of bytes required by the given data type.
Example in IL:
arr1:ARRAY[0..4] OF INT;
Var1 INT
LD arr1
ST |
Var1 (* Result is 10 *) |
Example in ST:
var1 := SIZEOF(arr1);
12.3 Bitstring Operators
12.3.1AND
Bitwise AND of bit operands. The operands should be of the type BOOL, BYTE, WORD or DWORD.
WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32
The IEC Operators |
• 291 |
Bitstring Operators |
|
|
|
Example in IL:
Var1 |
BYTE |
|
LD |
2#1001_0011 |
|
AND |
2#1000_1010 |
|
ST |
Var1 |
(* Result is 2#1000_0010 *) |
Example in ST:
var1 := 2#1001_0011 AND 2#1000_1010
Example in FBD:
Note:
If you have a program step in the SFC like the following
and if you use 68xxxor C-code generators, please note the following: The allocation of the value of the second input variable at the AND operator module to variable z will not be executed ! This is due to the optmized processing in the SFC in case of value FALSE at the input variable.
12.3.2OR
Bitwise OR of bit operands. The operands should be of the type BOOL,
BYTE, WORD or DWORD.
Example in IL:
var1 :BYTE;
LD |
2#1001_0011 |
OR |
2#1000_1010 |
ST |
var1 (* Result is 2#1001_1011 *) |
Example in ST:
Var1 := 2#1001_0011 OR 2#1000_1010
Example in FBD:
WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32
292 • The IEC Operators
Bitstring Operators
Note:
If you have a program step in the SFC like the following
and if you use 68xxxor C-code generators, please note the following: The allocation of the value of the second input variable at the AND operator module to variable z will not be executed ! This is due to the optmized processing in the SFC in case of value FALSE at the input variable.
12.3.3XOR
Bitwise XOR of bit operands. The operands should be of the type BOOL, BYTE, WORD or DWORD.
Example in IL:
Var1 :BYTE;
LD |
2#1001_0011 |
XOR |
2#1000_1010 |
ST |
Var1 (* Result is 2#0001_1001 *) |
Example in ST:
Var1 := 2#1001_0011 XOR 2#1000_1010
Example in FBD:
12.3.4NOT
Bitwise NOT of a bit operand. The operand should be of the type BOOL, BYTE, WORD or DWORD.
Example in IL:
Var1 :BYTE;
LD 2#1001_0011
NOT
WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32
|
The IEC Operators • 293 |
|
Bit-Shift Operators |
|
|
ST |
Var1 (* Result is 2#0110_1100 *) |
Example in ST:
Var1 := NOT 2#1001_0011
Example in FBD:
12.4 Bit-Shift Operators
Note:
The code generator for the Infineon C16x target system carries out bit-shift calculating operations with modulo 16.
12.4.1SHL
Bitwise left-shift of an operand : erg:= SHL (in, n)
The input variables erg, in and n should be of the type BYTE, WORD, or DWORD. in will be shifted to the left by n bits and filled with zeros on the right.
Note:
Please note, that the amount of bits, which is regarded for the arithmetic operation, is pretended by the data type of the input variable !. If the input variable is a constant the smallest possible data type is regarded. The data type of the output variable has no effect at all on the arithmetic operation.
See in the following example in hexadecimal notation that you get different results for erg_byte and erg_word depending on the data type of the input variable (BYTE or WORD), although the values of the input variables in_byte and in_word are the same.
Example in ST:
WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32