Introduction

An operator is a symbol for:

  • an arithmetic operation to be executed,

  • a logical operation to be executed or

  • calling an elementary function block - DFBs or subroutines.

Operators are generic, i.e. they adapt automatically to the data type of the operands.

Load and Save Operators

IL programming language load and save operators:

Operator

Modifier

Meaning

Operands

Description

LD

N

(only for operands of data type BOOL, BYTE, WORD or DWORD)

Loads the operands value into the accumulator

Literal, variable, direct address of any data type

The value of an operand is loaded into the accumulator using LD. The size of the accumulator adapts automatically to the data type of the operand. This also applies to the derived data types.

Example: In this example the value of A is loaded into the accumulator, the value of B then added and the result saved in E.

LD A

ADD B

ST E

ST

N

(only for operands of data type BOOL, BYTE, WORD or DWORD)

Saves the accumulator value in the operand

Variable, direct address of any data type

The current value of the accumulator is stored in the operand using ST. The data type of the operand must be the same as the "data type" of the accumulator.

Example: In this example the value of A is loaded into the accumulator, the value of B then added and the result saved in E.

LD A

ADD B

ST E

The "old" result is used in subsequent calculations, depending on whether or not an LD follows an ST.

Example: In this example the value of A is loaded into the accumulator, the value of B then added and the result saved in E. The value of B is then subtracted from the value of E (current accumulator content) and the result saved in C.

LD A

ADD B

ST E

SUB 3

ST C

Set and Reset Operators

Set and reset operators of the IL programming language:

Operator

Modifier

Meaning

Operands

Description

S

-

Sets the operand to 1, when the accumulator content is 1

Variable, direct address of BOOL data type

S sets the operand to "1" when the current content of the accumulator is a Boolean 1.

Example: In this example the value of A is loaded to the accumulator. If the content of the accumulator (value of A) is 1, then OUT is set to 1.

LD A

S OUT

Usually this operator is used together with the reset operator R as a pair.

Example: This example shows a RS flip-flop (reset dominant) that is controlled through the two Boolean variables A and C.

LD A

S OUT

LD C

R OUT

R

-

Sets the operand to 0 when the accumulator content is 1

Variable, direct address of BOOL data type

R sets the operand to "0" when the current content of the accumulator is a Boolean 1.

Example: In this example the value of A is loaded to the accumulator. If the content of the accumulator (value of A) is 1, then OUT is set to 0.

LD A

R OUT

Usually this operator is used together with the set operator S as a pair.

Example: This example shows a SR flip-flop (set dominant) that is controlled through the two Boolean variables A and C.

LD A

R OUT

LD C

S OUT

Logical Operators

IL programming language logic operators:

Operator

Modifier

Meaning

Operands

Description

AND

N, N(, (

Logical AND

Literal, variable, direct address of BOOL, BYTE, WORD or DWORD data types

The AND operator makes a logical AND link between the accumulator content and the operand.

In the case of BYTE, WORD and DWORD data types, the link is made bit by bit.

Example: In the example D is 1 if A, B and C are 1.

LD A

AND B

AND C

ST D

OR

N, N(, (

Logical OR

Literal, variable, direct address of BOOL, BYTE, WORD or DWORD data types

The OR operator makes a logical OR link between the accumulator content and the operand.

In the case of BYTE, WORD and DWORD data types, the link is made bit by bit.

Example: In the example D is 1 if A or B are 1 and C is 1.

LD A

OR B

OR C

ST D

XOR

N, N(, (

Logical exclusive OR

Literal, variable, direct address of BOOL, BYTE, WORD or DWORD data types

The XOR operator makes a logical exclusive OR link between the accumulator content and the operand.

If more than two operands are linked, the result with an uneven number of 1-states is 1, and is 0 with an even number of 1-states.

In the case of BYTE, WORD and DWORD data types, the link is made bit by bit.

Example: In the example D is 1 if A or B is 1. If A and B have the same status (both 0 or 1), D is 0.

LD A

XOR B

ST D

If more than two operands are linked, the result with an uneven number of 1-states is 1, and is 0 with an even number of 1-states.

Example: In the example F is 1 if 1 or 3 operands are 1. F is 0 if 0, 2 or 4 operands are 1.

LD A

XOR B

XOR C

XOR D

XOR E

ST F

NOT

-

Logical negation (complement)

Accumulator contents of data types BOOL, BYTE, WORD or DWORD

The accumulator content is inverted bit by bit with NOT.

Example: In the example B is 1 if A is 0 and B is 0 if A is 1.

LD A

NOT

ST B

Arithmetic Operators

IL programming language Arithmetic operators:

Operator

Modifier

Meaning

Operands

Description

ADD

(

Addition

Literal, variable, direct address of data types INT, DINT, UINT, UDINT, REAL or TIME

With ADD the value of the operand is added to the value of the accumulator contents.

Example: The example corresponds to the formula D = A + B + C

LD A

ADD B

ADD C

ST D

SUB

(

Subtraction

Literal, variable, direct address of data types INT, DINT, UINT, UDINT, REAL or TIME

With SUB the value of the operand is subtracted from the accumulator content.

Example: The example corresponds to the formula D = A - B - C

LD A

SUB B

SUB C

ST D

MUL

(

Multiplication

Literal, variable, direct address of data type INT, DINT, UINT, UDINT or REAL

The MUL operator multiplies the content of the accumulator by the value of the operand.

Example: The example corresponds to the formula D = A * B * C

LD A

MUL B

MUL C

ST D

Note: The MULTIME function in the obsolete library is available for multiplications involving the data type Time.

DIV

(

Division

Literal, variable, direct address of data type INT, DINT, UINT, UDINT or REAL

The DIV operator divides the contents of the accumulator by the value of the operand.

Example: The example corresponds to the formula D = A / B / C

LD A

DIV B

DIV C

ST D

Note: The DIVTIME function in the obsolete library is available for divisions involving the data type Time.

MOD

(

Modulo Division

Literal, variable, direct address of INT, DINT, UINT or UDINT data types

The MOD operator divides the value of the first operand by the value of the second and returns the remainder (Modulo) as the result.

Example: In this example

  • C is 1 if A is 7 and B is 2

  • C is 1 if A is 7 and B is -2

  • C is -1 if A is -7 and B is 2

  • C is -1 if A is -7 and B is -2

LD A

MOD B

ST C

Comparison Operators

IL programming language comparison operators:

Operator

Modifier

Meaning

Operands

Description

GT

(

Comparison: >

Literal, variable, direct address of data type BOOL, BYTE, WORD, DWORD, STRING, INT, DINT, UINT, UDINT, REAL, TIME, DATE, DT or TOD

The GT operator compares the contents of the accumulator with the contents of the operand. If the contents of the accumulator are greater than the contents of the operands, the result is a Boolean 1. If the contents of the accumulator are less than/equal to contents of the operands, the result is a Boolean 0.

Example: In the example the value of D is 1 if A is greater than 10, otherwise the value of D is 0.

LD A

GT 10

ST D

GE

(

Comparison: >=

Literal, variable, direct address of data type BOOL, BYTE, WORD, DWORD, STRING, INT, DINT, UINT, UDINT, REAL, TIME, DATE, DT or TOD

The GE operator compares the contents of the accumulator with the contents of the operand. If the contents of the accumulator are greater than/equal to the contents of the operands, the result is a Boolean 1. If the contents of the accumulator are less than the contents of the operands, the result is a Boolean 0.

Example: In the example the value of D is 1 if A is greater than or equal to 10, otherwise the value of D is 0.

LD A

GE 10

ST D

EQ

(

Comparison: =

Literal, variable, direct address of data type BOOL, BYTE, WORD, DWORD, STRING, INT, DINT, UINT, UDINT, REAL, TIME, DATE, DT or TOD

The EQ operator compares the contents of the accumulator with the contents of the operand. If the contents of the accumulator is equal to the contents of the operands, the result is a Boolean 1. If the contents of the accumulator are not equal to the contents of the operands, the result is a Boolean 0.

Example: In the example the value of D is 1 if A is equal to 10, otherwise the value of D is 0.

LD A

EQ 10

ST D

NE

(

Comparison: <>

Literal, variable, direct address of data type BOOL, BYTE, WORD, DWORD, STRING, INT, DINT, UINT, UDINT, REAL, TIME, DATE, DT or TOD

The NE operator compares the contents of the accumulator with the contents of the operand. If the contents of the accumulator are not equal to the contents of the operands, the result is a Boolean 1. If the contents of the accumulator are equal to the contents of the operands, the result is a Boolean 0.

Example: In the example the value of D is 1 if A is not equal to 10, otherwise the value of D is 0.

LD A

NE 10

ST D

LE

(

Comparison: <=

Literal, variable, direct address of data type BOOL, BYTE, WORD, DWORD, STRING, INT, DINT, UINT, UDINT, REAL, TIME, DATE, DT or TOD

The LE operator compares the contents of the accumulator with the contents of the operand. If the contents of the accumulator are less than/equal to the contents of the operands, the result is a Boolean 1. If the contents of the accumulator are greater than the contents of the operands, the result is a Boolean 0.

Example: In the example the value of D is 1 if A is smaller than or equal to 10, otherwise the value of D is 0.

LD A

LE 10

ST D

LT

(

Comparison: <

Literal, variable, direct address of data type BOOL, BYTE, WORD, DWORD, STRING, INT, DINT, UINT, UDINT, REAL, TIME, DATE, DT or TOD

The LT operator compares the contents of the accumulator with the contents of the operand. If the contents of the accumulator is less than the contents of the operands, the result is a Boolean 1. If the contents of the accumulator is greater than/equal to contents of the operands, the result is a Boolean 0.

Example: In the example the value of D is 1 if A is smaller than 10, otherwise the value of D is 0.

LD A

LT 10

ST D

Call Operators

IL programming language call operators:

Operator

Modifier

Meaning

Operands

Description

CAL

C, CN

(only if the accumulator contents are of the BOOL data type)

Call of a function block, DFB or subprogram

Instance name of the function block, DFB or subprogram

A function block, DFB or subprogram is called up conditionally or unconditionally with CAL.

see also Calling Elementary Function Blocks and Derived Function Blocks and Subroutine Call

FUNCTIONNAME

-

Executing a function

Literal, variable, direct address (data type is dependent on function)

A function is performed by specifying the name of the function.

see also Calling Elementary Functions

PROCEDURENAME

-

Executing a procedure

Literal, variable, direct address (data type is dependent on procedure)

A procedure is performed by specifying the name of the procedure.

see also Calling Procedures

Structuring Operators

IL programming language structuring operators:

Operator

Modifier

Meaning

Operands

Description

JMP

C, CN

(only if the accumulator contents are of the BOOL data type)

Jump to label

LABEL

With JMP a jump to the label can be conditional or unconditional.

see also Labels and Jumps

RET

C, CN

(only if the accumulator contents are of the BOOL data type)

Return to the next highest program organization unit

-

RETURN operators can be used in DFBs (derived function blocks) and in SRs (subroutines).

RETURN operators can not be used in the main program.

  • In a DFB, a RETURN operator forces the return to the program which called the DFB.

    • The rest of the DFB section containing the RETURN operator is not executed.

    • The next sections of the DFB are not executed.

    The program which called the DFB will be executed after return from the DFB.

    If the DFB is called by another DFB, the calling DFB will be executed after return.

  • In a SR, a RETURN operator forces the return to the program which called the SR.

    • The rest of the SR containing the RETURN operator is not executed.

    The program which called the SR will be executed after return from the SR.

)

-

Processing deferred operations

-

A right bracket ) starts the processing of the deferred operator. The number of right bracket operations must be equal to the number of left bracket modifiers. Brackets can be nested.

Example: In the example E is 1 if C and/or D is 1 and A and B are 1.

LD A

AND B

AND( C

OR D

)

ST E