Q. How are comparisons done in 8086 assembly language?
There is a compare instruction CMP. Though this instruction just sets the flags on comparing two operands (both 16 bits and 8 bits). Compare instruction just subtracts value of source from destination without storing result however setting the flag at the time of the process. Normally only 3 comparisons are more important. These are:
Result of comparison Flag(s) affected
Destination < source Carry flag = 1
Destination = source Zero flag = 1
Destination > source Carry = 0, Zero = 0
Let us look at 3 illustration which show how flags are set when numbers are compared. In illustration 1 BL is less than 10 so carry flag is set. In illustration 2 the zero flag is set since both operands are equal. In illustration 3 the destination (BX) is greater than source so both zero and carry flags are clear.
Example 1:
MOV BL, 02h
CMP BL, 10h; Carry flag = 1
Example 2:
MOV AX, F0F0h
MOV DX, F0F0h
CMP AX, DX; Zero flag = 1
Example 3:
MOV BX, 200H
CMP BX, 0; Zero and Carry flags = 0