<<< SUB Arithmetic Subtraction     Index     XOR Exclusive Or >>>


XCHG Exchange Operands

Flags affected:

        O D I T S Z A P C  OF: Overflow flag  TF: Trap flag AF: Aux carry
        F F F F F F F F F  DF: Direction flag SF: Sign flag PF: Parity flag
            <none>         IF: Interrupt flag ZF: Zero flag CF: Carry flag

Legal forms:

        XCHG r8,r8
        XCHG r8,m8
        XCHG r16,r16
        XCHG r16,m16
        XCHG r32,r32    386+
        XCHG r32,m32    386+

Examples:

        XCHG AL,DH
        XCHG BH,BYTE [SI]
        XCHG SP,BP
        XCHG DX,WORD [DI]  
        XCHG ESI,EDI
        XCHG ECX,DWORD [EBP+38]
        XCHG AX,BX   ; Uses single-byte opcode

Notes:

XCHG exchanges the contents of its two operands. This is why there is no form of XCHG for identical operands; that is, XCHG AX,AX is not a legal form since exchanging a register with itself makes no logical sense.

Exchanging an operand with AX may be accomplished with a single-byte opcode, saving fetch time and code space. All good assemblers recognize these cases and optimize for them, but if you are hand-assembling INLINE statements for some high-level language, keep the single-byte special cases in mind.

        r8 = AL AH BL BH CL CH DL DH        r16 = AX BX CX DX BP SP SI DI
        sr = CS DS SS ES FS GS              r32 = EAX EBX ECX EDX EBP ESP ESI EDI
        m8 = 8-bit memory data              m16 = 16-bit memory data
        m32 = 32-bit memory data            i8 = 8-bit immediate data
        i16 = 16-bit immediate data         i32 = 32-bit immediate data
        d8 = 8-bit signed displacement      d16 = 16-bit signed displacement
        d32 = 32-bit unsigned displacement


<<< SUB Arithmetic Subtraction     Index     XOR Exclusive Or >>>