Compare Halfword (CH)
The COMPARE HALFWORD instruction compares a half­ word in storage with the contents of a register. For example,
assume that:
Register 44 contains FF FF 80 00 = -32,768
10
Register 13 contains 00 01 60 50 Storage lQ(;ations 16080-16081 contain 8000 = -32,768
1
0
When the instruction
Machine Format 030 Assembler Format Op Code R
1
, O
2
(X
2
, 8
2
)
CH 4, X'30'(O, 13)
is executed, the contents oflocations 16080-16081 are
fetched, expanded to 32 bits (the sign bit is propagated to
the left), and compared with the contents of register 4. Be­ cause the two numbers are equal, condition code 0 is set.
Compare logical (Cl, ClR, CLI, ClC)
The COMPARE LOGICAL instructions differ from the
algebraic instructions (C, CR) in that all quantities are
handled as if unsigned.
Compare Logical (CL R)
Assume that:
Register 1 contains 00 00 00 01 Register 2 contains FF FF FF FF
Execution of the instruction
Machine Format Op Code R1 R2 Assembler Format Op Code R
1
, R2
CLR 1,2
sets condition code 1. A condition code 1 indicates that the
first operand is lower than the second. However, if an
algebraic compare instruction had been executed, condition
code 2 would have been set, indicating that the first oper­ and is higher. During algebraic comparison, the contents of
register 1 are interpreted as + 1 and the contents of register
2 as -1. During logical comparison, the leftmost byte of
register 2 is compared with the leftmost byte of register 1;
each byte is interpreted as a binary number. In this case:
Leftmost byte of register 1: 0000 0000 2 010 Leftmost byte of register 2: 1111 11112 =:: 25510
294 System/370 Principles of Operation If the leftmost bytes are equal, the next two bytes are
compared, etc., until either an inequality is discovered or
the contents of the registers are exhausted.
Compare Logical Immediate (CLI) The CLI instruction logically compares a byte from the
instruction stream with a byte from storage. For example,
assume that:
Register 10 contains 00 00 17 00 Storage location 1703 contains 7E
Execution of the instruction
Machine Format Op Code 0
1
95
AF I A I 003 Assembler Format
o p Code 0
1
(8
1
), 12 CLI 3(10),X'AF'
sets condition code 1, indicating that the first operand (the
quantity in main storage) is lower than the second (imme­ diate) operand.
Compare Logical Characters (CLC)
The COMPARE LOGICAL CHARACTERS instruction can
be used to perform the logical comparison of storage fields
up to 256 bytes in length. For example, assume that the
following two fields of data are in storage:
Field 1
1886 1891 I 01 1
06
1 C81 05
1
E2/ 06
1
05
1
68
I C1 1
48
I C2148 I Field 2 1900 1908 I 01 I 06 I C81 05
1
E2 I 06
1
05
1
68 I C
1 1
48
I C31 48 I Also assume:
Register 6 contains 00 00 18 80 Register 7 con tains 00 00 19 00 Execution of the instruction
Machine Format Op Code L 05 08 006 Assembler Format Op Code 0
1
(L, 8
1
), O
2
(8
2
)
CLC 6(12,6),0(7) 000 sets condition code 2, indicating that the contents of field
1 are higher in value than the contents of field 2.
Because CLC compares bytes on an unsigned binary basis,
the instruction can be used to collate fields composed of
characters from the EBCDIC code. For example, in EBCDIC the above two data fields are:
Field 1 JOHNSON ,A.B.
Field 2 JOHNSON,A.C. Condition code 1 tells us that A. B. JOHNSON precedes
A. C. JOHNSON, thus placing the names in the correct
alphabetic order.
Compare logical Characters Under Mask (ClM)
The CLM instruction provides a means of comparing selected
bytes of a word contained in a general register to a contig­
uous field of bytes in main storage. The M3 field of the CLM instruction is a four-bit mask that selects zero through four
bytes from a general register, each mask bit corresponding
left to right with a selected register byte. In the compari­
son, the selected register bytes are treated as a contiguous
field, and the operands are considered as binary unsigned
quantities, with all codes valid. The operation proceeds
left to right. For example, assume that:
Three bytes starting at storage location 10200 contain FO BC 7B
Register 12 contains 10 000 Register 6 contains FO BC 5C 7B
Execution of the instruction
Machine Format 200 Assembler Format Op Code R
1
, M
3
, D2 (8
2
) ClM 6,8'1101',X'200'(12) produces the following result:
Register 6: FO Mask (D) FO Three bytes starting at location 10200 8C 8C 5C o
78
1
78
Result: Condition code 0 is set (selected bytes are equal,
or mask is zero). Register 6 and bytes in main
storage are unchanged. Other condition codes would indicate:
Condition Code,'
1 Selected field of first operand (register contents)
is less than second operand (storage locations)
2 Selected field of first operand is greater than
second operand
3
Compare logical long (ClCL)
The CLCL instruction is used to logically compare two
operands in main storage. Each operand can be up to
16,777,215 bytes in length. Two pairs of even-odd general
registers are used to locate the operands and to control the
execution of the CLCL instruction, which can be inter­
rupted in progress. The first register of each pair must be
an even register, and it is used to contain the storage location
of the byte currently being compared in each operand. The
odd register of each pair contains the length of the operand
it covers, and the high-order byte of the second-operand
odd register contains a padding character which is used to
logically extend a shorter operand to the same length as a
longer operand. The following illustrates the assignment of
registers for CLCL: R1 (Even) First-Operand Address I 0 8 31
R1+1 (Odd) First-Operand length I 0 8 31
R2 (Even) Second-Operand Address 0 8 31
R2+1 (Odd) Pad Char. Second-Operand length
o 8 31
The following instructions set up two register pairs to
control a text-string comparison. For example, assume: Operand 1
Address: 20800 (hex)
Length: 100 (dec) Operand 2
Address: 20AOO (hex)
Length: 132 (dec) Pad Character
AddIess: 20003 (hex)
Length: 1
Value: 40 (hex)
Register 12 contains 00 02 00 00 The setup instructions are:
LA 4,X'800' (12) Point register 4 to the start of the first
operand
LA 5,100 Set register 5 to the length of first operand
LA 8,X'AOO'(12) Point register 8 to the start of second
operand
LA 9,132 Set register 9 to the length of second
operand
ICM 9,B'1000',3(12) Insert padding character (blank) into byte
o of register 9.
The register pair 4-5 is now covering the first operand.
Bits 8-31 of register 4 contain the storage location of the
start of an EBCDIC text string, and bits 8-31 of register 5
contain the length of the string, in this case 100 bytes.
Appendix I. Number Representation and Instruction-Use Examples 295
Previous Page Next Page