User Guide
General-Purpose Programming 43
24592—Rev. 3.15—November 2009 AMD64 Technology
The CMOVcc instructions perform the same task as MOV but work conditionally, depending on the
state of status flags in the RFLAGS register. If the condition is not satisfied, the instruction has no
effect and control is passed to the next instruction. The mnemonics of CMOVcc instructions indicate
the condition that must be satisfied. Several mnemonics are often used for one opcode to make the
mnemonics easier to remember. For example, CMOVE (conditional move if equal) and CMOVZ
(conditional move if zero) are aliases and compile to the same opcode. Table 3-4 shows the RFLAGS
values required for each CMOVcc instruction.
In assembly languages, the conditional move instructions correspond to small conditional statements
like:
IFa=bTHENx=y
CMOVcc instructions can replace two instructions—a conditional jump and a move. For example, to
perform a high-level statement like:
IF ECX = 5 THEN EAX = EBX
without a CMOVcc instruction, the code would look like:
cmp ecx, 5 ; test if ecx equals 5
jnz Continue ; test condition and skip if not met
mov eax, ebx ; move
Continue: ; continuation
but with a CMOVcc instruction, the code would look like:
cmp ecx, 5 ; test if ecx equals to 5
cmovz eax, ebx ; test condition and move
Replacing conditional jumps with conditional moves also has the advantage that it can avoid branch-
prediction penalties that may be caused by conditional jumps.
Support for CMOVcc instructions depends on the processor implementation. To find out if a processor
is able to perform CMOVcc instructions, use the CPUID instruction.
Table 3-4. rFLAGS for CMOVcc Instructions
Mnemonic Required Flag State Description
CMOVO OF = 1 Conditional move if overflow
CMOVNO OF = 0 Conditional move if not overflow
CMOVB
CMOVC
CMOVNAE
CF=1
Conditional move if below
Conditional move if carry
Conditional move if not above or equal
CMOVAE
CMOVNB
CMOVNC
CF=0
Conditional move if above or equal
Conditional move if not below
Conditional move if not carry
CMOVE
CMOVZ
ZF=1
Conditional move if equal
Conditional move if zero