The Compare Halfword instruction is used to compare a binary fullword in a register, Operand 1, with a binary halfword in memory, Operand 2.  The operands are compared as 2’s complement signed binary integers.  For purposes of comparison, the halfword is “sign-extended” to a fullword before the comparison occurs.  This extension occurs internally and is temporary.  The instruction sets the condition code to indicate how Operand 1 compares to Operand 2:

                              

                      Condition Code               Meaning                            Test With

 

                                0                    Operand 1 = Operand 2                 BE, BZ

                                1                    Operand 1 < Operand 2                 BL, BM

                                2                    Operand 1 > Operand 2                 BH, BP

                             

 

                            CH    R9,AFIELD       

 

 

   The contents of the halfword “AFIELD”, x012C’, is signed extended to a fullword, x’0000012C’, and is compared to the contents of register 9 which contains x’000045FF’.  Since the contents of the register (Operand 1) is greater than the value than the extended halfword (Operand 2), the condition code is set to “High”.  The condition code in the diagram above is specified using 2 binary digits.  After comparison, the condition code is set to a binary 10 which is 2 in decimal - a “High” condition.

 

   Since CH is an RX instruction, an index register may be coded as part of operand 2 (see Explicit Addressing).

 

 

 

 

 

 

        Some Unrelated Compare Halfwords

 

              R4 =  X’FFFFFFD5’  -43 IN 2’S COMPLEMENT

              R5 =  X’00000028’  +40 IN 2’S COMPLEMENT

              R6 =  X’00000004’   +4 IN 2’S COMPLEMENT

  

              DOG   DC   H’40’

              CAT   DC   H’-30’

              PIG   DC   H’14’

              GOAT  DC   H’3’

 

              CH    R4,=H’20’    CONDITION CODE = LOW

              CH    R4,=H’-50’   CONDITION CODE = HIGH

              CH    R5,=H’20’    CONDITION CODE = HIGH

              CH    R6,=H’4’     CONDITION CODE = EQUAL

              CH    R5,=H’40’    CONDITION CODE = EQUAL

              CH    R5,DOG       CONDITION CODE = EQUAL

              CH    R6,DOG(R6)   CONDITION CODE = LOW

                                 DOG(R6) IS EQUIVALENT TO PIG