CLC Instruction

The CLC (compare logical characters) instruction compares the first and second operands and sets the condition code to reflect the result of the comparison. The comparison is a logical comparison (not a numeric comparison), so it is used for character data. The two operands are compared bit by bit until a difference is found or until all bits are compared and the operands are found to be equal. The condition code is set as follows:

Relation of Operands Result of Comparison Value of Condition Code
operand1 == operand2 equal 00
operand1 < operand2 low 01
operand1 > operand2 high 10

Given the following definitions:

ONE      DC     C'ABCDE'
TWO      DC     C'12345'
THREE    DC     C'ABX1239'
FOUR     DC     C'ABC'
FIVE     DC     C'123'
SIX      DC     C' ABCD'
SEVEN    DC     C'BBC'

The DC statements shown above result in the following data (shown in character and hex) in storage:

A B C D E 1 2 3 4 5 A B X 1 2 3 9 A B C 1 2 3   A B C D B B C


ONE       TWO       THREE         FOUR  FIVE  SIX       SEVEN

The following table shows the results of CLC instructions. Each instruction starts with the initial data given above.

CLC Instruction Operand 1 Operand 2 Result Condition Code
Implicit Comparisons
CLC ONE,TWO C1C2C3C4C5 F1F2F3F4F5 low 01
CLC ONE,FOUR C1C2C3C4C5 C1C2C3F1F2 low 01
CLC FOUR,ONE C1C2C3 C1C2C3 equal 00
CLC SEVEN,FOUR C2C2C3 C1C2C3 high 10
CLC FOUR,SIX+1 C1C2C3 C1C2C3 equal 00
CLC ONE,SIX C1C2C3C4C5 40C1C2C3C4 high 10
CLC THREE,ONE C1C2E7F1F2F3F9 C1C2C3C4C5F1F2 high 10
Explicit Comparisons
CLC TWO(3),FIVE F1F2F3 F1F2F3 equal 00
CLC THREE+3(3),FIVE F1F2F3 F1F2F3 equal 00
CLC FIVE(8),TWO F1F2F340C1C2C3C4 F1F2F3F4F5C1C2E7 low 01
CLC SIX+2(1),SEVEN+1 C2 C2 equal 00

Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2003