Data Transfer Instructions The data transfer instructions will copy data from one location (either register or memory) to another location (either register or memory). The Intel 80386 has several data transfer instructions. This lesson will discuss the mov, lea, and xchg data transfer instructions. The MOV Instruction Syntax: mov dst, src The mov instruction will copy the content of src into dst. The src operand can be a register, memory location, or a value (decimal value, hexadecimal value, etc.) while the dst operand can either be a register, or a memory location. Examples: mov ax, 23 ; will store the decimal value 23 into the register ax ; content of ax in binary format is 0000 0000 0001 0111 ; content of ax in hexadecimal format is 0017h mov bx, 98h; will store the hexadecimal value 98 into the register bx ; content of bx in binary format is 0000 0000 1001 1000 ; content of bx in hexadecimal format is 0098h mov dx, ax ; will copy the content of register ax into register dx mov yy1, bl ; will copy the content of register bl into memory location or variable yy1 (this assumes that yy1 had been previously declared using the db directive). The LEA Instruction Syntax: lea dst, src The lea instruction will copy the memory address of src into dst. The src operand is always a memory location while the dst operand is always a register. lea stands for load effective address. In the following example, assume that a portion of memory is as shown in figure 1 below. Example: lea eax, xx1 ; copy the memory address of xx1 into register eax ; after executing this instruction, eax = 4000 0302h Figure 1: Portion of sample memory The XCHG Instruction Syntax: xchg opr1, opr2 The xchg instruction will exchange the contents of opr1 and opr2. The operands opr1 and opr2 can be either a register or a memory location but neither can be a value. Examples: mov ax, 10 ; ax = 10 decimal mov bx, 20 ; bx = 20 decimal xchg ax, bx ; ax = 20 decimal, bx = 10 decimal mov y, 5 ; y = 5 decimal (assume that y had been ; previously declared using the db directive) mov cl, 35 ; cl = 35 decimal xchg y, cl ; y = 35 decimal, cl = 5 decimal Restrictions Using the data transfer instructions requires that a few restrictions be observed. These restrictions are enumerated and discussed below. 1. The source and destination operands must have the same size Examples: mov al, bx ; invalid instruction because the destination operand (al) is 8 bits wide ; while the source operand (bx) is 16 bits wide. mov z, ch ; valid instruction if the destination operand (z) was declared previously ; using the db directive which is the same size as the source operand ch ; (8 bits) otherwise the instruction is invalid mov esi, dx; invalid instruction since the destination operand (esi) is 32 bits wide ; while the source operand is only 16 bits wide. mov di, bp; valid instruction since both the destination operand (di) and the source ; operand (bp) have the same size (16 bits). 2. Data cannot be copied between memory locations directly. In the example below, assume that both x and y are 8-bit memory locations. Example: mov x, y ; invalid instruction since the destination operand (x) and the source ; operand (y) are both memory locations. To copy the content of y ; into x, use an appropriate register as in the following: ; mov al, y ; mov x, al 3. Data cannot be copied between segment registers directly. Example: mov ds, es ; invalid instruction since the destination operand (ds) and the source ; operand (es) are both segment registers. To copy the content of es ; into ds, use an appropriate register as in the following: ; mov bx, es ; mov ds, bx 4. The destination operand cannot be a value (decimal value, hexadecimal value, etc.) Example: mov 45, al ; invalid instruction since the destination operand (45) is a value. 5. The eip register cannot be used as a destination operand Example: mov eip, ebx ; invalid instruction since eip is used as the destination operand.