Assembly language instructions XCHG: exchange two operands content

XCHG (exchange data) exchange two instruction operands content. This instruction has three forms:

 

XCHG reg, reg
XCHG reg, mem
XCHG mem, reg

In addition XCHG instruction MOV instruction not used for other than immediate operand, the number of required operations XCHG instruction "MOV instruction" is described in a number of operations required is the same.

Sorting array applications, XCHG instructions provide an easy way to exchange two array elements. The following are several examples of the use of XCHG instruction.

  xchg ax, bx; exchange 16-bit register contents xchg ah, al; exchange 8-bit register contents xchg var1, bx; 16 exchange memory operand with register BX the content xchg eax, ebx; exchange 32-bit register contents

If you want to exchange two memory operand, the register as a temporary container, with the MOV instruction using the instruction XCHG:

  mov ax,val1  xchg ax,val2  mov val1,ax

4.1  Operand Type
4.2  MOV instructions
4.3  MOVZX to doing it and instructions MOVSX
4.4  LAHF SAHF instruction and
4.5 of 5  XCHG instructions
4.6  immediate offset operands
4.7  assembly language data transfer Example
4.8  addition and subtraction Detailed
4.9  the OFFSET operator
4.10  the ALIGN directive
4.11  the PTR operator
4.12  the TYPE operator
4.13  lengthof operator
4.14  the LABEL directive
4.15  indirect addressing
4.16  the JMP and LOOP instruction
4.17  64 MOV instruction
4.18  64-bit addition and subtraction

Guess you like

Origin blog.csdn.net/Javaxuxuexi/article/details/93401513