IL mnemonics

⚠️ Deprecated

The third edition of IEC 61131-3 (2013) removed IL from the standard. matiec still accepts IL for round-trip with legacy projects, but new POUs should use ST.

If you have IL POUs in an inherited project, this page lists the instruction set so you can read and migrate them. The single-accumulator model is straightforward to translate to ST: each LD <var> starts a new ST expression chain, each arithmetic instruction extends the chain, and each ST <var> terminates the chain with an assignment.

The accumulator model

Every IL instruction operates on the current result (CR) — a single implicit register. The CR’s type is whatever the last instruction set it to.

LD  iA          (* CR := iA *)
ADD iB          (* CR := CR + iB *)
ST  iResult     (* iResult := CR *)

is equivalent to ST:

iResult := iA + iB;

Load and store

MnemonicOperandMeaning
LDvar or literalCR := operand
LDNvar (BOOL)CR := NOT operand (BOOL only)
STvarvar := CR
STNvar (BOOL)var := NOT CR
Svar (BOOL)If CR is TRUE: var := TRUE (set)
Rvar (BOOL)If CR is TRUE: var := FALSE (reset)

Arithmetic

MnemonicOperandMeaning
ADDvar or literalCR := CR + operand
SUBCR := CR - operand
MULCR := CR * operand
DIVCR := CR / operand
MODCR := CR MOD operand

Bitwise / logical

MnemonicOperandMeaning
AND, &CR := CR AND operand
ANDN, &NCR := CR AND NOT operand
ORCR := CR OR operand
ORNCR := CR OR NOT operand
XORCR := CR XOR operand
XORNCR := CR XOR NOT operand
NOTCR := NOT CR

Comparison

MnemonicOperandMeaning
GTCR := CR > operand
GECR := CR >= operand
EQCR := CR = operand
NECR := CR <> operand
LECR := CR <= operand
LTCR := CR < operand

Branch

MnemonicOperandMeaning
JMPlabelunconditional jump
JMPClabeljump if CR is TRUE
JMPCNlabeljump if CR is FALSE
RETreturn from function/FB
RETCreturn if CR is TRUE
RETCNreturn if CR is FALSE

Labels are written label: on their own line:

LD     xMode
JMPC   skip
LD     iA
ADD    iB
ST     iResult
skip:  LD  xDone
       ST  xFlag

Function and FB calls

MnemonicOperandMeaning
CALinstance(args)unconditional call of FB instance
CALCcall if CR is TRUE
CALCNcall if CR is FALSE

Function calls use the function name directly with parentheses:

LD     iA
ABS                        (* CR := ABS(iA) *)
ST     iAbs

LD     instance.OUT        (* read FB output *)

Parenthesised expressions

( defers the operation until the matching ). Inside the parens, the CR builds up an expression that’s then combined with the outer CR using the deferred operator:

LD    iA
ADD   ( iB
        MUL iC )           (* CR := iA + (iB * iC) *)
ST    iResult

This is the IL equivalent of operator precedence — without parens IL is strictly left-to-right.

Migration to ST

The mechanical translation:

IL patternST equivalent
LD a / ST bb := a;
LD a / ADD b / ST cc := a + b;
LD a / GT b / ST xx := a > b;
LDN a / ST bb := NOT a;
JMPC l1 ... l1:IF cond THEN ... END_IF; (refactor as needed)
CAL inst(p := v)inst(p := v); (same syntax in ST)

Most legacy IL POUs translate to a few-line ST equivalent. The hardest cases are deeply nested parens with many JMPC labels — those usually map to IF/ELSIF cascades or CASE.

IEC reference

IEC 61131-3 second edition (2003), clause 6.5 — defined the IL instruction set. The third edition (2013) removed IL.

matiec conformance

matiec accepts IL per the second-edition spec. New code should be written in ST.