CMP

VAX11

 

CMP     COMPARE

 

Purpose

arithmetic comparison between two scalar quantities

Format

opcode srcl.rx, src2.rx

Operation

srcl - src2;

Condition codes

N ß srcl LSS src2;

Z ß srcl EQL src2;

V ß 0;

C ß srcl LSSU src2 (integer);

C ß C (floating);

Exceptions

None (integer); reserved operand (floating point)

Opcodes

91        CMPB             Compare Byte

Bi         CMPW            Compare Word

Dl         CMPL             Compare Long

51        CMPF             Compare Floating

71        CMPD             Compare Double

Description

The source 1 operand is compared with the source 2 operand. The only action is to affect the condition codes.

Notes

On a floating reserved operand fault, the condition codes are unpredictable.

 

 

Example 1

 

The following program demonstrates condition branches that effected from CMP results.

 

.text

 

main: .word 0

 

      movb $10, r1

      movb $5, r2

 

      # first case - should be True

      cmpb r1, r2

      bgtr eq1

      calls $0, prn_false

      jmp next_stage

eq1:  calls $0, prn_true

 

      # second case - should be False

next_stage:

      cmpb r2, r1

      bgtr eq2

      calls $0, prn_false

      jmp end_prog

eq2:  calls $0, prn_true

 

end_prog:

      pushl $0

      calls $1, .exit

 

prn_false: .word 0

      pushal lbl_false

      pushal format

      calls $2, .printf

      ret

prn_true: .word 0

      pushal lbl_true

      pushal format

      calls $2, .printf

      ret

 

.data

 

lbl_true:   .asciz "True"

lbl_false: .asciz "False"

format:     .asciz "%s\n"