XCHG—Exchange Register/Memory with RegisterInstruction Operand EncodingDescriptionExchanges the contents of the destination (first) and source (second) operands. The operands can be two general-purpose registers or a register and a memory location. If a memory operand is referenced, the processor’s locking protocol is automatically implemented for the duration of the exchange operation, regardless of the presence or absence of the LOCK prefix or of the value of the IOPL. (See the LOCK prefix description in this chapter for more information on the locking protocol.)This instruction is useful for implementing semaphores or similar data structures for process synchronization. (See “Bus Locking” in Chapter 8 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A, for more information on bus locking.) The XCHG instruction can also be used instead of the BSWAP instruction for 16-bit operands.In 64-bit mode, the instruction’s default operation size is 32 bits. Using a REX prefix in the form of REX.R permits access to additional registers (R8-R15). Using a REX prefix in the form of REX.W promotes operation to 64 bits. See the summary chart at the beginning of this section for encoding data and limits.OpcodeInstructionOp/ En64-Bit ModeCompat/Leg ModeDescription90+rwXCHG AX, r16OValidValidExchange r16 with AX.90+rwXCHG r16, AXOValid ValidExchange AX with r16.90+rdXCHG EAX, r32OValid ValidExchange r32 with EAX.REX.W + 90+rdXCHG RAX, r64OValidN.E.Exchange r64 with RAX.90+rdXCHG r32, EAXOValid ValidExchange EAX with r32.REX.W + 90+rdXCHG r64, RAXOValidN.E.Exchange RAX with r64.86 /rXCHG r/m8, r8MRValid ValidExchange r8 (byte register) with byte from r/m8.REX + 86 /rXCHG r/m8*, r8*MRValidN.E.Exchange r8 (byte register) with byte from r/m8.86 /rXCHG r8, r/m8RMValid ValidExchange byte from r/m8 with r8 (byte register).REX + 86 /rXCHG r8*, r/m8*RMValidN.E.Exchange byte from r/m8 with r8 (byte register).87 /rXCHG r/m16, r16MRValidValidExchange r16 with word from r/m16.87 /rXCHG r16, r/m16RMValid ValidExchange word from r/m16 with r16.87 /rXCHG r/m32, r32MRValid ValidExchange r32 with doubleword from r/m32.REX.W + 87 /rXCHG r/m64, r64MRValidN.E.Exchange r64 with quadword from r/m64.87 /rXCHG r32, r/m32RMValid ValidExchange doubleword from r/m32 with r32.REX.W + 87 /rXCHG r64, r/m64RMValid N.E.Exchange quadword from r/m64 with r64.NOTES:*In 64-bit mode, r/m8 can not be encoded to access the following byte registers if a REX prefix is used: AH, BH, CH, DH. Op/EnOperand 1Operand 2Operand 3Operand 4OAX/EAX/RAX (r, w)opcode + rd (r, w)NANAOopcode + rd (r, w)AX/EAX/RAX (r, w)NANAMRModRM:r/m (r, w)ModRM:reg (r)NANARMModRM:reg (w)ModRM:r/m (r)NANA
This UNOFFICIAL reference was generated from the official Intel® 64 and IA-32 Architectures Software Developer’s Manual by a dumb script. There is no guarantee that some parts aren't mangled or broken and is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.