Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture
Vol. 1 7-5
PROGRAMMING WITH GENERAL-PURPOSE INSTRUCTIONS
These conditional move instructions are supported in the P6 family, Pentium 4, and
Intel Xeon processors. Software can check if CMOVcc instructions are supported by
checking the processor’s feature information with the CPUID instruction.
7.3.1.2 Exchange Instructions
The exchange instructions swap the contents of one or more operands and, in some
cases, perform additional operations such as asserting the LOCK signal or modifying
flags in the EFLAGS register.
The XCHG (exchange) instruction swaps the contents of two operands. This instruc-
tion takes the place of three MOV instructions and does not require a temporary loca-
tion to save the contents of one operand location while the other is being loaded.
When a memory operand is used with the XCHG instruction, the processor’s LOCK
signal is automatically asserted. This instruction is thus useful for implementing
semaphores or similar data structures for process synchronization. See “Bus
Locking” in Chapter 7, “Multiple-Processor Management,” of the Intel® 64 and IA-32
Architectures Software Developer’s Manual, Volume 3A, for more information on bus
locking.
The BSWAP (byte swap) instruction reverses the byte order in a 32-bit register
operand. Bit positions 0 through 7 are exchanged with 24 through 31, and bit posi-
tions 8 through 15 are exchanged with 16 through 23. Executing this instruction
twice in a row leaves the register with the same value as before. The BSWAP instruc-
tion is useful for converting between “big-endian” and “little-endian” data formats.
This instruction also speeds execution of decimal arithmetic. (The XCHG instruction
can be used to swap the bytes in a word.)
Table 7-2. Conditional Move Instructions
Instruction Mnemonic Status Flag States Condition Description
Unsigned Conditional Moves
CMOVA/CMOVNBE (CF or ZF) =
0 Above/not below or equal
CMOVAE/CMOVNB CF = 0 Above or equal/not below
CMOVNC CF = 0 Not carry
CMOVB/CMOVNAE CF = 1 Below/not above or equal
CMOVC CF = 1 Carry
CMOVBE/CMOVNA (CF or ZF) = 1 Below or equal/not above
CMOVE/CMOVZ ZF = 1 Equal/zero
CMOVNE/CMOVNZ ZF = 0 Not equal/not zero
CMOVP/CMOVPE PF = 1 Parity/parity even
CMOVNP/CMOVPO PF = 0 Not parity/parity odd