Section Description Page
11.1 Overview 11-2
11.2 Comparing Two Integers 11-3
11.3 Comparing Two Floating-Point Numbers 11-5
Chapter Overview
11
11.1 Overview
You can use the Compare instructions to compare the following pairs of numeric values:
Two integers (16 bits)
Two double integers (32 bits)
Two real numbers (IEEE floating-point, 32 bits)
You load the numeric values into accumulators 1 and 2. A Compare instruction compares the value in accumulator 2 to the value in accumulator 1 according to the criteria listed in Table 11-1.
The result of the comparison is a binary digit, that is, either a 1 or a 0. A 1 indicates that the result of the comparison is true; a 0 indicates that the result of the comparison is false (see Table 11-2). This result is stored in the result of logic operation bit (RLO bit, see Section 3.4). You can use this result in your program for further processing.
When the CPU executes a Compare instruction, it also sets bits in the status word. Other statement list instructions can evaluate the bits of the status word. The CPU executes Compare instructions without regard to the result of logic operation.
Table 11-1 Criteria for Comparisons Type of Numeric Value in
Accumulator 2
Comparison Criterion Symbol(s) for Instruction Type of Numeric Value in Accumulator 1
is equal to ==I
==D
==R
is not equal to <>I
<>D
<>R Integer (16 bits)
Double integer (32 bits)
is greater than >I
>D
>R
Integer (16 bits) Double integer (32 bits)
g ( )
Real number
(floating-point, 32 bits)
is less than <I
<D
<R
g ( )
Real number
(floating-point, 32 bits) is greater than or equal to >=I
>=D
>=R is less than or equal to <=I
<=D
<=R Comparison Instructions
11.2 Comparing Two Integers
The Compare Integer instructions compare two single integers (16 bits each) and the Compare Double Integer instructions compare two double integers (32 bits each) according to the criteria listed in Table 11-2. A sample program follows Table 11-3.
Table 11-2 Compare Integer and Compare Double Integer Instructions
Instruction Explanation
Instruct on Explanat on
==I
==D
The integer in the low word of accumulator 2 is equal to the integer in the low word of accumulator 1.
The double integer in accumulator 2 is equal to the double integer in accumulator 1.
<>I
<>D
The integer in the low word of accumulator 2 is not equal to the integer in the low word of accumulator 1.
The double integer in accumulator 2 is not equal to the double integer in accumulator 1.
>I
>D
The integer in the low word of accumulator 2 is greater than the integer in the low word of accumulator 1.
The double integer in accumulator 2 is greater than the double integer in accumulator 1.
<I
<D
The integer in the low word of accumulator 2 is less than the integer in the low word of accumulator 1.
The double integer in accumulator 2 is less than the double integer in accumulator 1.
>=I
>=D
The integer in the low word of accumulator 2 is greater than or equal to the integer in the low word of accumulator 1.
The double integer in accumulator 2 is greater than or equal to the double integer in accumulator 1.
<=I
<=D
The integer in the low word of accumulator 2 is less than or equal to the integer in the low word of accumulator 1.
The double integer in accumulator 2 is less than or equal to the double integer in accumulator 1.
Description
Comparison Instructions
A Compare Integer or Compare Double Integer instruction sets certain combinations in the CC 1 and CC 0 bits to indicate what condition has been fulfilled (see Table 11-3).
Table 11-3 Settings of Bits CC 1 and CC 0 after a Compare Instruction Condition Signal states of CC 1 and CC 0: Possible check
with the instructions
The following sample program shows how the Compare instructions for integers (16 bits) work.
STL Explanation
Load the contents of memory word MW10 into accumulator 1.
Load the contents of input word IW0 into accumulator 1. The old contents of accumulator 1 are shifted to accumulator 2.
Compare the value in the low word of accumulator 2 to the value in the low word of accumulator 1 to see if they are equal.
Output Q 4.0 will be energized if MW10 and IW0 are equal.
Compare the value in the low word of accumulator 2 to see if it is greater than the value in the low word of
accumulator 1.
Output Q 4.1 will be energized if MW10 is greater than IW0.
Compare the value in the low word of accumulator 2 to see if it is less than the value in the low word of
accumulator 1.
Output Q 4.2 will be energized if MW10 is less than IW0.
Setting Bits CC 1 and CC 0 of the Status Word
Example
Comparison Instructions
11.3 Comparing Two Floating-Point Numbers
The Compare Floating-Point Number instructions compare two 32-bit IEEE floating-point numbers according to the criteria listed in Table 11-4. Because IEE 32-bit floating-point numbers belong to the data type called “REAL,”
the mnemonic abbreviation for these instructions is R.
Table 11-4 Compare Real Instructions (IEEE 32-bit Floating-Point Numbers)
Instruction Explanation
Instruct on Explanat on
==R The IEEE 32-bit floating-point number in accumulator 2 is equal to the IEEE 32-bit floating-point number in accumulator 1.
<>R The IEEE 32-bit floating-point number in accumulator 2 is not equal to the IEEE 32-bit floating-point number in accumulator 1.
>R The IEEE 32-bit floating-point number in accumulator 2 is greater than the IEEE 32-bit floating-point number in accumulator 1.
<R The IEEE 32-bit floating-point number in accumulator 2 is less than the IEEE 32-bit floating-point number in accumulator 1.
>=R The IEEE 32-bit floating-point number in accumulator 2 is greater than or equal to the IEEE 32-bit floating-point number in accumulator 1.
<=R The IEEE 32-bit floating-point number in accumulator 2 is less than or equal to the IEEE 32-bit floating-point number in accumulator 1.
A Compare Real number instruction sets certain combinations in the CC 1, CC 0, OV, and OS bits of the status word to indicate what condition has been fulfilled.
Table 11-5 Settings of Bits of the Status Word after a Compare Real Instruction (IEEE 32-bit Floating-Point Numbers)
Condition CC 1 CC 0 OV OS
== 0 0 0 not applicable
<>
0 or 1
1 or 0
0 not applicable
> 1 0 0 not applicable
< 0 1 0 not applicable
1 0
Description
Setting Bits of the Status Word
Comparison Instructions
Other statement list instructions can evaluate the bits of the status word (see Section 5.3 and Table 11-6).
Table 11-6 Instructions That Evaluate the CC 1, CC 0, OV, and OS Bits of the Status Word
Instruction Reference to Bits of the Status Word or Jump Label
Section in this Manual A,O,X,AN,ON,XN >0, <0, <>0, >=0, <=0, ==0, UO, OV, OS 5.3
JUO <jump label> 16.4
JZ <jump label> 16.5
JN <jump label> 16.5
JP <jump label> 16.5
JM <jump label> 16.5
JMZ <jump label> 16.5
JPZ <jump label> 16.5
The following sample program shows how the Compare Real number instructions work.
STL Explanation
L MD24 L +1.00E+00
>R
= Q 4.1
<R
= Q 4.2
Load the contents of memory double word MD24 into accumulator 1.
Load the value 1 as a 32-bit floating-point number into accumulator 1.
The old contents of accumulator 1 are shifted to accumulator 2.
Compare the value in accumulator 2 to see if it is greater than the value in accumulator 1.
Output Q 4.1 will be energized if MD24 is greater than 1.
Compare the value in accumulator 2 to see if it is less than the value in accumulator 1.
Output Q 4.2 will be energized if MD24 is less than 1.
Evaluating the Bits of the Status Word
Example
Comparison Instructions