CMP Command

    Another instruction you will see quite often is the CMP or compare instruction. This instruction compares the two "variables" and changes the flags register accordingly. The source and destination operands are the same as those for the move instruction. Let's consider an example in which the AX register holds 21 and the BX register holds 22. Then "CMP AX,BX" is performed.

    The compare instruction is like a subtraction instruction, but it doesn't change the contents of the AX register. So, when 22 is subtracted from 21, the answer will be -1, but we will never see the answer, only the flags which have resulted from the operation. Number 21 is less than 22, so the carry flag and the sign flag should be set. Just remember that when the carry flag is set, the first number is less than the second number. The same is true for the sign flag. Why have two flags if they tell us the same thing? This is more complicated and you should not concern yourself with it. It requires knowledge of hexadecimal arithmetic, the denotation of signed and unsigned integers.

Return