CMP AX, loc16
6-74
CMP AX, loc16 Compare
SYNTAX OPTIONS OPCODE OBJMODE RPT CYC
CMP AX, loc16 0101 010A LLLL LLLL X − 1
Operands AX Accumulator high (AH) or accumulator low (AL) register
loc16 Addressing mode (see Chapter 5)
Description The content of the specified AX register (AH or AL) is compared with the 16-bit
content of the location pointed to by the “loc16” addressing mode. The result
of (AX−- [loc16] ) is evaluated and the status flag bits set accordingly. The AX
register and content of the location pointed to by “loc16” are left unchanged:
Set Flags On (AX − [loc16]);
Flags
and
Modes
N
If the result of the operation is negative, then N is set; otherwise it is cleared.
The CMP instruction assumes infinite precision when it determines the sign of
the result. For example, consider the subtraction 0x8000 − 0x0001. If the
precision were limited to 16 bits, the result would cause an overflow to the
positive number 0x7FFF and N would be cleared. However, because the CMP
instruction assumes infinite precision, it would set N to indicate that
0x8000 − 0x0001 actually results in a negative number.
Z
The comparison is tested for a zero condition. The zero flag bit is set if the
operation ( AX − [loc16] ) = 0, otherwise it is cleared.
C
If the subtraction generates a borrow, then C is cleared; otherwise C is set.
Repeat This instruction is not repeatable. If this instruction follows the RPT
instruction, it resets the repeat counter (RPTC) and executes only once.
Example
; Branch if VarA is higher then VarB:
MOV AL,@VarA ; Load AL with contents of VarA
CMPB AL,@VarB ; Set Flags On (AL − VarB)
SB Dest,HI ; Branch if VarA higher then VarB