xchg

8086 and later

Exchange Register/Memory with Register

xchg ax, reg16 | xchg rax, reg64 | xchg reg16, ax | xchg reg64, rax | xchg eax, reg32na | xchg reg32na, eax | xchg eax, eax | xchg reg8, r/m8 | xchg reg16, r/m16 | xchg reg32, r/m32 | xchg reg64, r/m64 | xchg r/m8, reg8 | xchg r/m16, reg16 | xchg r/m32, reg32 | xchg r/m64, reg64

XCHG exchanges the values in its two operands. It can be used with a LOCK prefix for purposes of multi-processor synchronisation.

XCHG AX,AX or XCHG EAX,EAX (depending on the BITS setting) generates the opcode 90h, and so is a synonym for NOP (NOP).

Loading...

Forms

Every form of xchg the assembler accepts, from NASM's own instruction table. The second column is the processor that introduced the form; a badge marks a form that needs an extension, that is lockable, or that long mode dropped.

FormSinceNotes
xchg ax, reg168086
xchg rax, reg64x86-64long
xchg reg16, ax8086
xchg reg64, raxx86-64long
xchg eax, reg32na386
xchg reg32na, eax386
xchg eax, eax386nolong
xchg reg8, r/m88086lock1
xchg reg16, r/m168086lock1
xchg reg32, r/m32386lock1
xchg reg64, r/m64x86-64lock1long
xchg r/m8, reg88086lock
xchg r/m16, reg168086lock
xchg r/m32, reg32386lock
xchg r/m64, reg64x86-64locklong