You are on page 1of 2

S7-200 Programmable Controller System Manual

Compare Instructions
Comparing Numerical Values
The compare instructions are used to compare two values:
IN1 = IN2 IN1 >= IN2 IN1 <= IN2
IN1 > IN2 IN1 < IN2 IN1 <> IN2
Compare Byte operations are unsigned.
Compare Integer operations are signed.
Compare Double Word operations are signed.
Compare Real operations are signed.
When the comparison is true, the
Compare instruction turns on the contact (LAD) or output
(FBD).
When the comparison is true, the Compare
instruction Loads, ANDs, or ORs a 1 with the value on the
top of the stack (STL).
When you use the IEC compare instructions, you can use
various data types for the inputs. However, both input
values must be of the same data type.

Notice
The following conditions are fatal errors and cause your
S7-200 to immediately stop the execution of your
program:
Illegal indirect address is encountered (any Compare
instruction)
Illegal real number (for example, NAN) is encountered
(Compare Real instruction)
To prevent these conditions from occurring, ensure that
you properly initialize pointers and values that contain real
numbers before executing compare instructions that use
these values.
Compare instructions are executed regardless of the state
of power flow.

Table 6-15 Valid Operands for the Compare Instructions


Inputs/Outputs Type Operands
IN1, IN2 BYTE IB, QB, VB, MB, SMB, SB, LB, AC, *VD, *LD, *AC, Constant
INT IW, QW, VW, MW, SMW, SW, T, C, LW, AC, AIW, *VD, *LD, *AC,
Constant
DINT ID, QD, VD, MD, SMD, SD, LD, AC, HC, *VD, *LD, *AC, Constant
REAL ID, QD, VD, MD, SMD, SD, LD, AC, *VD, *LD, *AC, Constant
Output (or OUT) BOOL I, Q, V, M, SM, S, T, C, L, Power Flow

96
S7-200 Programmable Controller System Manual

Compare String
The Compare String instruction compares two strings of
ASCII characters:
IN1 = IN2 IN1 <> IN2
When the comparison is true, the Compare instruction turns
the contact (LAD) or output (FBD) on, or the compare
instruction Loads, ANDs or ORs a 1 with the value on the
top of the stack (STL).

Notice
The following conditions are fatal errors and cause your
S7-200 to immediately stop the execution of your
program:
Illegal indirect address is encountered (any compare
instruction)
A string with a length greater than 254 characters is
encountered (Compare String instruction)
A string whose starting address and length are such
that it will not fit in the specified memory area
(Compare String instruction)
To prevent these conditions from occurring, ensure that
you properly initialize pointers and memory locations that
are intended to hold ASCII strings prior to executing
compare instructions that use these values. Ensure that
the buffer reserved for an ASCII string can reside
completely within the specified memory area.
Compare instructions are executed regardless of the state
of power flow.

Table 6-16 Valid Operands for the Compare String Instructions


Inputs/Outputs Type Operands
IN1 STRING VB, LB, *VD, *LD, *AC, constant
IN2 STRING VB, LB, *VD, *LD, *AC
Output (OUT) BOOL I, Q, V, M, SM, S, T, C, L, Power Flow

98

You might also like