Example for a PLC programming language LD

Instruction list (STL)

TwinCAT PLC Control: languages

An instruction list (STL) consists of a sequence of instructions. Each instruction begins on a new line and contains an operator and, depending on the type of operation, one or more operands separated by commas.
An identifier can be placed in front of an instruction, followed by a colon (:).
A comment must be the last element on a line. Empty lines can be inserted between statements.


Example:


LD 17
ST lint (* Comment *)
GE 5
JMPC next
LD idword
EQ istruct.sdword
STN test
next:

Modifiers and operators in IL


The following operators and modifiers can be used in the IL language.
Modifiers:

  • C for JMP, CAL, RET: The instruction is only executed if the result of the previous expression is TRUE.
  • N for JMPC, CALC, RETC: The instruction is only executed if the result of the preceding expression is FALSE.
  • N otherwise: negation of the operand (not of the accumulator)

In the following you will find a table of all operators in STL with their possible modifiers and the respective meaning:

operatorModifiersimportance
LDNSet the current result equal to the operand
STNSave the current result to the operand position
S.Set the Boolean operand to TRUE exactly if the current result is TRUE
R.
ANDN, (Bitwise AND
ORN, (Bitwise OR
XOR(Bitwise exclusive OR
ADD(addition
SUB(subtraction
MUL(multiplication
DIV(division
GT(>
GE(>=
EQ(=
NE(<>
LE(<=
LT(<
JMPCNJump to the mark
CALCNCall function block
RETCNLeave the block and return to the caller if necessary
)Evaluate deferred operation

A list of all IEC operators can be found in the appendix.

Example of an STL program using some modifiers:

LD TRUE (* Load TRUE into the accumulator *)
ANDN BOOL1 (* execute AND with the negated value of the variable BOOL1 *)
JMPC mark (* if the result was TRUE, jump to the mark "mark" *)
LDN BOOL2 (* Save the negated value of *)
ST ERG (* BOOL2 in ERG *)
brand:

LD BOOL2 (* save the value of *)
ST ERG (* BOOL2 in ERG *)


In STL it is also possible to put brackets after an operation. The value of the bracket is then considered as the operand.
For example:

LD 2
MUL 2
ADD 3
ST Erg


Here is the value of Erg 7. But if you put brackets:

LD 2
MUL (2
ADD 3

ST Erg


The result here is the value for Erg 10, because the MUL operation is only evaluated when ")" is encountered; the operand for MUL is then 5.