CMP Command
Compares the first source operand with the second source operand and sets the status
flags in the EFLAGS (refers to the extended Flags, for a brief description of
how flags work, please review 4.2) register according to the results. The
comparison is performed by subtracting the second operand from the first operand
and then setting the status flags in the same manner as the SUB instruction.
When an immediate value is used as an operand, it is sign-extended to the length
of the first operand.
The CMP instruction is typically used in conjunction with a conditional jump (Jcc),
condition move (CMOVcc), or SETcc instruction. The condition codes used by the
Jcc, CMOVcc, and SETcc instructions are based on the results of a CMP
instruction. Below, there is a pseudo code fragment to demonstrate how the CPU behaves
upon the execution of a CMP command:
temp -> SRC1 - SignExtend(SRC2);
ModifyStatusFlags; /* Modify status flags in the same manner as the SUB instruction*/
Return