You are on page 1of 10

Lecture on: Data Transfer Instructions The XCHG Instruction

XCHG instruction Swaps data between two registers or a register and memory location

Mnemonic XCHG
Destination Accumulator Memory Register Register

Meaning Exchange
Source Reg 16 Register Register Memory

Format XCHG D,S

Operation (s) (D)

Flags affected None

NO XCHG: MEMs SEG REGs

Example: XCHG [1234h], BX


Swap the data between register BX and A word at memory location at offset 1234H

Ex: For the data shown in the figure what is the result of executing the following Instruction XCHG [1234H], BX
Execution of this instruction performs the function (DSx10 +1234H) (BX)
Address 8088 MPU 0101 1100 1200 IP CS DS SS ES AX BX CX DX SP BP SI DI 11101 11102 11103 11104 11105 12000 12001 Memory content 87 1E 34 12 XX xx xx Instruction XCHG [1234H], BX

Next instruction

11

AA

13234 13235

FF 00

(DS) =1200H, EA or Ofset address =1234H, The PA=12000H+1234H= 13234H The data at this address is FFH and the address that follows contains 11H. Execution of this instruction performs the following 16-bit swap: (13234H) (BL) (13235H) (BH) Thus we get (BX)= 00FFH [DS:1234]=11AAH
8088 MPU 0105 1100 1200 IP CS DS SS ES AX BX CX DX SP BP SI DI 11101 11102 11103 11104 11105 12000 12001 Memory content 87 1E 34 12 XX xx xx Instruction XCHG [1234H], BX

Address

Next instruction

00

FF

13234 13235

AA 11

The XLAT Instruction


Mnemonic
XLAT

Meaning
Translate

Format
XLAT

Operation
((AL)+(BX)+(DS)0) (AL)

Flags
None

The XLAT instruction simplifies implementation of lookup table. Example: Assume (DS) = 0300H, (BX)=0100H, and (AL)=0DH. Here 0Dh represent the ASCII character CR. Execution of XLAT replaces the contents of Al by the contents of memory location with physical address PA=(DS)0 +(BX) +(AL) = 03000H + 0100H + 0DH = 0310DH Thus (0310DH) (AL) Assuming this memory locations contains 52H (EBCDIC code for CR) this value is placed in AL. That is (AL)=52h.

The LEA, LDS, LES Instructions:


Mnemonic LEA LDS Meaning Load Effective Address Load Register And DS Load Register and ES Format LEA Reg16,EA LDS Reg16,MEM32 EA (MEM32) (Mem32+2) (MEM32) (Mem32+2) Operation (Reg16) (Reg16) (DS) (Reg16) (ES) Flags affected None None

LES

LES Reg16,MEM32

None

The following two instructions are equivalent, however, the second is more Efficient. LEA SI, DATA or MOV SI, Offset DATA Example: LEA SI,[DS:2345H] will load SI=2345H

Ex: assume (DI) = 1000H, (DS) = 1000H, content of P.A. 11000H=[11000H] =>7AH, [11001H]=>12H, [11002H]=>00H, [11003H]=>30H. What happens if the following instruction is executed.

LDS BX, [DI];

After execution BX DI DS 127A 1000 3000

Before execution xxxx 1000 (1000)0

7A 12 00 30

P.A. 11000 11001 11002 11003

Register BX is loaded from location DSx10+1000H= 11000H Register DS is loaded from 11002H.

LES similar to LDS except that it loads ES in addition to the specified regisetr

Ex: Assuming that the 8088 is initialized as shown in the following figure. What is the result of executing the following instruction? LDS SI, [200H] This instruction loads SI from memory location at physical location PA= 12000H + 200H = 12200H DS is loaded with the contents of the following two bytes at address 12202H
Address 8088 MPU 0100 1100 1200 IP CS DS SS ES AX BX CX DX SP BP SI DI 11100 11101 11102 11103 11104 12000 12001 Memory content C5 36 00 02 XX xx xx Instruction LDS SI, [200H]

Next instruction

12200 12201 12202 12203

20 00 00 13

xxxx

After execution
Address 8088 MPU 0104 1100 1300 IP CS DS SS ES AX BX CX DX SP BP SI DI 11100 11101 11102 11103 11104 12000 12001 Memory content C5 36 00 02 XX xx xx Instruction LDS SI, [200H]

Next instruction

12200 12201 12202 12203

20 00 00 13

0020

13000 13001

xx xx

New data segment

Ex: Assuming that the 8088 is initialized as shown in the following figure. What is the result of executing the following instruction? LES SI, [200H] This instruction loads SI from memory location at physical location PA= 12000H + 200H = 12200H and ES is loaded with the contents of the following two bytes at address 12202H
Address 8088 MPU 0100 1100 1200 IP CS DS SS ES AX BX CX DX SP BP SI DI 11100 11101 11102 11103 11104 12000 12001 Memory content C4 36 00 02 XX xx xx Instruction LES SI, [200H]

Next instruction

12200 12201 12202 12203

20 00 00 13

xxxx

After execution of LES SI, [200H]


Address 8088 MPU 0104 1100 1200 1300 IP CS DS SS ES AX BX CX DX SP BP SI DI 11100 11101 11102 11103 11104 12000 12001 Memory content C4 36 00 02 XX xx xx Instruction LES SI, [200H]

Next instruction

12200 12201 12202 12203

20 00 00 13

0020

13000 13001

xx xx

New data segment

You might also like