Академический Документы
Профессиональный Документы
Культура Документы
IL Editor: an Overview
Accumulator | Accumulator Stack | Nested Operations | Comments | IL Logic Examples
The Instruction List (IL) editor is an intelligent, free-form text editor for editing Instruction List
logic. You can configure the IL editor as to the format and color coding of the IL logic you create,
as well as the behavior of the editor itself. Default indentation rules can be applied while editing or
you can beautify an entire block with a single command. Contextual smart list support is provided
for almost every entry you make, allowing you to choose from a list, labels, variables and
instructions when they are expected.
There two basic methods for entering IL logic:
Right-click, choose Insert, then choose Variable or Keyword. A smart list appears
prompting you to choose a valid item, or create a new item.
Start typing and a smart list will appear listing your valid choices depending on where you
are typing (Quick-edit method).
The IL editor supports cut, copy and paste using the Windows Clipboard, allowing you to interact
with other text-based editors such as Notepad. You can drag and drop between the IL editor and
other Machine Edition tools, such as the Toolchest and the Variable list.
Few restrictions are placed on the way you work in the IL editor. The editor allows the entry of
undefined operands so you can type references to labels or variables that don't yet exist. Any
unresolved references are detected upon validation and easily located and corrected.
Register type
Accumulator
Number of Register
types
1
Accumulator stack 1
Data types
BOOL, DINT,
LREAL
BOOL, DINT,
LREAL
The Accumulator
IL logic is accumulator based, much like the assembler languages used for programming
microprocessors. When IL logic is executed by a PC, a single accumulator is used as a working
register. The accumulator is common to all IL blocks for each target with an IL block logic
component in it.
The accumulator can be of data type BOOL, DINT or LREAL, depending upon the data type of the
value loaded into it. For example, if the result of the current operation is BOOL, the accumulator
will be BOOL.
Most IL instructions operate on the contents of the accumulator and the accumulator stack. The
content of the accumulator is retained until modified by an operation, until the data type changes
(for example, DINT to LREAL), or the IL block has completed execution.
The accumulator can only contain a single data value.
Please refer to the IL logic examples below.
Note: The accumulator and the operand must always be the same data type.
Automatically received from the accumulator, since the accumulator can only contain one
data value.
The same data type as the accumulator.
Never directly used as part of an operation.
The content of the accumulator stack is retained until modified by an operation, until the
data type changes (for example, DINT to LREAL), or the IL block has completed execution.
Nested Operations
IL syntax allows for nested operations using the ADD, AND, ANDN, NOT, OR, ORN, XOR, XORN,
SUB, MUL, DIV, MOD, GT, GE, EQ, NE, LT, LE, LD and ST execution instructions where the
expected operand is an operation resulting in a BOOL, DINT or LREAL value.
A maximum of ten levels of nesting are supported.
No control instructions may be placed within nested operations.
Note: The accumulator and the result of the operand (which may be a nested operation) must always be of the same data
type; that is, BOOL, DINT or LREAL.
Comments
It is good practice to document your IL logic with detailed comments to aid yourself and others in
understanding the code. The IL editor provides two types of comments:
Block comments are contained between (* and *). Any text that appears between these
delimiters will be ignored by the compiler. Block comments can span one or more lines. For
example,
Inline comments are prefixed by ' and terminated by a line break. For example.
IL Logic Examples
Please refer to the four IL logic examples below for examples of valid and invalid IL logic, nested
operations, use of the accumulator, the accumulator stack and comments.
Refer to the table below to see the data values of the accumulator and the accumulator stack.
Line Accumulator
Accumulator stack
BOOLA
NULL
BOOLB
BOOLA
BOOLB OR BOOLC
BOOLA
BOOLA
BOOLD
BOOLD OR BOOLE
BOOLD OR BOOLE
BOOLA
10
BOOLA
11
BOOLA
12
BOOLA
13
NULL
Refer to the table below to see the data values of the accumulator and the accumulator stack.
Line
Accumulator
Accumulator stack
NULL
(A + B)
(A + B) * C
NULL
(A + B) * C
A
(A + B) * C
B
A
(A + B) * C
(D * C)
B
A
(A + B) * C
(D * C) + B
A
(A + B) * C
10
A - ((D * C) + B)
(A + B) * C
11
NULL
12
NULL
Note: In IL logic, there is no operator precedence. Each operator is executed as it occurs, unless a nested operation is
encountered, in which case the innermost nested operation is executed first.
ABS
Square Root
SQRT
Cosine
COS
Sine
SIN
Tangent
TAN
Arc Cosine
ACOS
Arc Sine
ASIN
Arc Tangent
ATAN
ATAN2
Hyperbolic Cosine
COSH
Hyperbolic Sine
SINH
Hyperbolic Tangent
TANH
Degrees to Radians
DTOR
Radians to Degrees
RTOD
Log
LOG
Natural Log
LN
Natural Exponent
EXP
EXPT
PC IL Instructions
DIV
MOD
Note: The accumulator and the operand must always be the same data type.
LE
LT
Note: The accumulator and the operand must always be the same data type.
ABS (operand)
The result of this instruction can be DINT or LREAL; therefore, the accumulator may be
DINT or LREAL.
IL and LD functions are generally the same, with some differences in data types for
operands.
ln operand
accumulator
ln(operand)
Calculate the natural (base e) logarithm of the operand and store the result
in the accumulator.
Operand: DINT, LREAL variable or constant.
For more details, see ln (LD).
Notes
LOG operand
accumulator
LOG(operand)
Calculate the base 10 logarithm of the operand and store the result in the
accumulator.
operand: DINT, LREAL variable or constant.
For more details, see LOG (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
If the operand is too large, the result will be zero.
IL and Ladder functions are generally the same, with some differences in data types for
operands.
DTOR operand
accumulator
DTOR (operand)
Convert the operand (angle in degrees) to radians and store the result in the
accumulator (angle in radians).
Operand: DINT, LREAL variable or constant.
For more details, see DTOR (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and LD functions are generally the same, with some differences in data types for
operands.
RTOD operand
accumulator
RTOD (operand)
Convert the operand (angle in radians) to degrees and store the result in the
accumulator (angle in degrees).
Operand: DINT, LREAL variable or constant.
For more details, see RTOD (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and LD functions are generally the same, with some differences in data types for
operands.
EXP operand
accumulator
eoperand
Calculate the natural exponent of e and store the result in the accumulator.
Operand: DINT, LREAL variable or constant.
For more details, see EXP (LD).
Notes
EXPT operand
accumulator
EXPT(accumulatoroperand)
Calculate the base (content of the accumulator) to the power of the operand
and store the result in the accumulator.
operand: DINT, LREAL variable or constant.
Example:
LD 2.0 'load accumulator; accumulator becomes LREAL
EXPT 3.5 'calculate 2.03.5 and store the result in the accumulator
COSH operand
accumulator
COSH(operand)
Calculate the hyperbolic cosine of the operand (in radians) and store the
result in the accumulator.
The angle is returned in radians.
Operand: DINT, LREAL variable or constant.
For more details, see COSH (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.
SINH operand
accumulator
SINH(operand)
Calculate the hyperbolic sine of the operand (in radians) and store the result
in the accumulator.
The angle is returned in radians.
Operand: DINT, LREAL variable or constant.
For more details, see SINH (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.
TANH operand
accumulator
TANH(operand)
Calculate the hyperbolic tangent of the operand (in radians) and store the
result in the accumulator.
Operand: DINT, LREAL variable or constant.
For more details, see TANH (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and LD functions are generally the same, with some differences in data types for
operands.
ACOS operand
accumulator
ACOS(operand)
Calculate the inverse cosine of the operand (in radians) and store the result
in the accumulator.
The operand must be in the range -1 to +1.
The angle is returned in radians, in the range 0 to pi.
Operand: DINT, LREAL variable or constant where (-1
operand
1).
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
An operand outside of the range (-1
operand
IL and Ladder functions are generally the same, with some differences in data types for
operands.
ASIN operand
accumulator
ASIN(operand)
Calculate the inverse sine of the operand (in radians) and store the result in
the accumulator.
The operand must be in the range -1 to +1.
The angle is returned in radians, in the range -pi/2 to +pi/2.
operand
1).
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
An operand outside of the range (-1
operand
IL and Ladder functions are generally the same, with some differences in data types for
operands.
ATAN operand
accumulator
ATAN(operand)
Calculate the inverse tangent of the operand (in radians) and store the result
in the accumulator.
The angle is returned in radians, in the range -pi/2 to +pi/2.
Operand: DINT, LREAL variable or constant.
For more details, see ATAN (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.
ATAN2 operand
accumulator
ATAN2(operand/accumulator)
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.
COS operand
accumulator
COS(operand)
Calculate the cosine of the operand and store the result in the accumulator.
The angle is returned in radians.
Operand: DINT, LREAL variable or constant.
For more details, see COS (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.
SIN operand
accumulator
SIN(operand)
Calculate the sine of the operand and store the result in the accumulator.
The angle is returned in radians.
Operand: DINT, LREAL variable or constant.
For more details, see SIN (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.
TAN operand
accumulator
TAN(operand)
Calculate the tangent of the operand and store the result in the accumulator.
The angle is returned in radians.
Operand: DINT, LREAL variable or constant.
For more details, see TAN (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.
operand
Calculate the square root of the operand and store the result in the
accumulator.
Operand: DINT, LREAL variable or constant.
For more details, see SQRT (LD).
Notes
The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
A negative operand causes the result to be zero.
IL and Ladder functions are generally the same, with some differences in data types for
operands.