Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
10
Добавлен:
11.10.2020
Размер:
3.39 Mб
Скачать

290 The IEC Operators

Bitstring Operators

Example in IL:

LD

9

MOD

2

ST

Var1 (* Result is 1 *)

Example in ST:

var1 := 9 MOD 2;

Example in FBD:

12.2.6INDEXOF

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

SIZEOF

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

294 The IEC Operators

Bit-Shift Operators

Example in FBD:

Example in IL:

LD 16#45

SHL 2

ST erg_byte

12.4.2SHR

Bitwise right-shift of an operand: erg:= SHR (in, n)

erg, in and n should be of the type BYTE, WORD or DWORD. in will be shifted to the right by n bits and filled with zeros on the left.

See the following example in hexadecimal notation to notice the results of the arithmetic operation depending on the type of the input variable (BYTE or WORD).

Example in ST:

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

The IEC Operators

295

Bit-Shift Operators

 

 

 

Example in FBD:

Example in IL:

LD 16#45

SHL 2

ST erg_byte

12.4.3ROL

Bitwise rotation of an operand to the left: erg:= ROL (in, n)

erg, in and n should be of the type BYTE, WORD or DWORD. in will be shifted one bit position to the left n times while the bit that is furthest to the left will be reinserted from 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

296 The IEC Operators

Bit-Shift Operators

Example in FBD:

Example in IL:

LD 16#45

SHL 2

ST erg_byte

12.4.4ROR

Bitwise rotation of an operand to the right: erg = ROR (in, n)

erg, in and n should be of the type BYTE, WORD or DWORD. in will be shifted one bit position to the right n times while the bit that is furthest to the left will be reinserted from the left.

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