Previous Topic: FormatNext Topic: Condition Codes Produced by the COMPARE Command


Compare Values of Two Accumulators

You can use the COMPARE command to compare the values of two accumulators. The following statement compares the value of the accumulator A1 with the value of the accumulator A2:

COMPARE A1,A2

The result of the comparison is represented by a condition code that indicates the relationship between A1 and A2. The condition code is then set and can be examined by the next statement in the program, a BRANCH statement that uses it to determine where to go next.

In the following program, ACL/E compares the values of accumulators A1 and A2. Because the values are equal, the program branches to the statement labeled EQUAL, which types the message "A1 and A2 are equal." If the values were not equal, the program would execute the statement immediately following the BRANCH statement, which types the message "A1 and A2 are not equal."

          SET A1,10 
          SET A2,10 
          COMPARE A1,A2 
          BRANCH EQ,EQUAL 
          KEY 'A1 and A2 are not equal.' 
          STOP 
EQUAL     KEY 'A1 and A2 are equal.'
          STOP