| ||The compare instruction (CMP) can be used to compare two numbers or test conditions
| ||When comparing numbers, at most one of these numbers can reside in memory
| ||The CMP instruction updates the arithmetic flags by performing: destination - source
| ||Unlike the SUB instruction the destination operand is not affected
| ||The values of the status flags are set according to the result of the subtraction
| ||The flags can be tested by a subsequent conditional jump instruction
The CMP instruction has the following format:
CMP destination, source
Observing the following rules:
| || The destination can be a register or memory operand
| ||The source can be a register, memory operand, or an immediate operand
| ||At most one of the operands may reside in memory.
A conditional jump instruction is usually used after a CMP instruction
This gives the ability to split the program flow into one of two paths
depending upon some logical condition.
As an example, the following code increments the AX register if BX is equal to CX.
CMP BX, CX ;Compare BX to CX
JNE SkipStmt ;If BX ≠ CX skip
INC AX ;AX = AX + 1