›› Comparing Data
Index
The compare instructions does nothing more than compare two values and set a condition
code based on the result. You can then use this condition code to make decisions in your program.
The condition code is set to the following after the compare instruction is completed:
CC is 0 if values are equal CC is 1 if left < right (left low) CC is 2 if right > left (left high)
Compare Register (CR) instruction
This compare instructions compare 32-bit binary integers and do not change the data being compared. Remember the binary data is stored is two's complement and if looking at the hex value you need to double to to ensure the sign of the value you are looking at. As this a numeric data this instruction and the C instruction compares the comparision is done algebraically.
CR Instruction format
+--------+---+---+
| op-code| R1| R2| 4 bytes long x '19'
+--------+---+---+
0 8 15
Format:
CR R1,R2
CR 8,6 /* */
Assume the following registers contain the following HEX values:
R8 = 00000222 and R6 = 00000222 -> CC is 0 (equal)
R8 = 00000000 and R6 = 00000222 -> CC is 1 (left low )
R8 = 00000999 and R6 = 00000222 -> CC is 2 (left high)
R8 = 98765432 and R6 = 12345678 -> CC is 1 (left low )
R8 = 98765432 and R6 = 98765431 -> CC is 2 (left high)
The last two contains negitive number where it starts with 9 (1001).
98765432 is a bigger negitive number than 98765431.
Compare Register (C) instruction
C Instruction format
This instruction functions the same as the previous CR instruction but instead of 2 registers it compares the content of a register with a 31 binary number at a storage location.
+--------+---+---+---+---+---+---+
| op-code| R1| X2| B2| D2 | 4 bytes long x'59'
+--------+---+---+---+---+---+---+
0 8 16 24 31
Format:
C R1,D2(X2,B2)
Compare halfword (CH) instruction
CH Instruction format
This instruction also functions the same as the previous CR instruction but instead of 2 registers it compares the content of a register with the high order 16 bits (2 bytes) signed binary integer in a storage location. The register is treated as a signed binary 32 bit value.
+--------+---+---+---+---+---+---+
| op-code| R1| X2| B2| D2 | 4 bytes long x'49'
+--------+---+---+---+---+---+---+
0 8 16 24 31
Format:
CH R1,D2(X2,B2)
Compare Logical Register (CLR) instruction
The compare logical instructions does a logical compare instead of a mathematical or arithmetical comparison.
The content of this data isn't signed when numbers are represented. The compare is done left to right and stops as
soon as a unequal value is found.
The condition codes is set as follows after the compare is completed:
CC is 0 if values are equal CC is 1 if left < right (left low) CC is 2 if right > left (left high)
CLR Instruction format
+--------+---+---+
| op-code| R1| R2| 2 bytes long x '15'
+--------+---+---+
0 8 15
Format:
CLR R1,R2
Assume the following registers contain the following HEX values:
R8 = 98765432 and R6 = 12345678 -> CC is 2 (left high)
R8 = 98765432 and R6 = 98765431 -> CC is 2 (left high)
CLR 8,6 /* */
Compare this result with the previous result from the CR instruction.
Compare Logical (CL) instruction
This is also a logical compare as discussed in CLR and functions the same way as the CLR instruction.
The content of a register is compared toa unsigned 32 bit storage area.
The condition codes is set as follows after the compare is completed:
CC is 0 if values are equal CC is 1 if left < right (left low) CC is 2 if right > left (left high)
CL Instruction format
+--------+---+---+---+---+---+---+
| op-code| R1| X2| B1| D1 | 4 bytes long x '55'
+--------+---+---+---+---+---+---+
0 8 16 24 31
Format:
CL R1,D2(X2,B2)
Assume the following registers contain the following HEX values:
R8 = FFFFFFF0 and DATA = FFFFFFFF -> CC is 1 (left LOW )
CL 8,DATA /* */
Compare Logical Immediate (CLI) instruction
Another logical compare but no registers will be used. Storage areas will be compared as unsigned integers.
Condition codes is set as in previous instructions.
CLI Instruction format
+--------+---+---+---+---+---+---+
| op-code| I2 | B1| D1 | 4 bytes long x '95'
+--------+---+---+---+---+---+---+
0 8 16 24 31
Format:
CLI D1(B1),I2
CLI1 CLI DATA,C'X' /* */
********************************************************************
CLI2 L R8,SOMEDATA /* Load 4 bytes in R8 where */
/* SOMEDATA resolved too. */
CLI 3(R8),C'#' /* Compare 4th byte in R8 */
BE MATCH /* to 'X' and branch is =. */
Compare Logical Character (CLC) instruction
Compares two storage areas and set a condition code.
Condition codes is set as in previous instructions.
CLC Instruction format
+--------+---+---+---+---+---+---+---+---+---+---+
| op-code| L | B1| D1 | B2| D2 | 6 bytes long x'D5'
+--------+---+---+---+---+---+---+---+---+---+---+
0 8 16 20 32 36 47
Format:
CLC D1(L,B1),D2(B2)
CLC DATA(10),MOREDATA /* */
MOREDATA is compares to DATA for a length of 10 bytes.
Links