Intel 253666-024US User Manual

Page 170

Advertising
background image

3-124 Vol. 2A

CMP—Compare Two Operands

INSTRUCTION SET REFERENCE, A-M

Description

Compares the first source operand with the second source operand and sets the
status flags in the EFLAGS 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 condition codes used by the Jcc, CMOVcc, and SETcc instructions are based on
the results of a CMP instruction. Appendix B, “EFLAGS Condition Codes,” in the
Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, shows
the relationship of the status flags and the condition codes.
In 64-bit mode, the instruction’s default operation size is 32 bits. Use of the REX.R
prefix permits access to additional registers (R8-R15). Use of the REX.W prefix
promotes operation to 64 bits. See the summary chart at the beginning of this
section for encoding data and limits.

Operation

temp ← SRC1 − SignExtend(SRC2);

ModifyStatusFlags; (* Modify status flags in the same manner as the SUB instruction*)

Flags Affected

The CF, OF, SF, ZF, AF, and PF flags are set according to the result.

Protected Mode Exceptions

#GP(0)

If a memory operand effective address is outside the CS, DS,

ES, FS, or GS segment limit.

If the DS, ES, FS, or GS register contains a NULL segment

selector.

#SS(0)

If a memory operand effective address is outside the SS

segment limit.

#PF(fault-code)

If a page fault occurs.

#AC(0)

If alignment checking is enabled and an unaligned memory

reference is made while the current privilege level is 3.

#UD

If the LOCK prefix is used.

Real-Address Mode Exceptions

#GP

If a memory operand effective address is outside the CS, DS,

ES, FS, or GS segment limit.

#SS

If a memory operand effective address is outside the SS

segment limit.

Advertising