40
Prof. Fayez F. M. El-Sousy Prof. Fayez F. M. El Prof. Fayez F. M. El - - Sousy Sousy Department of Electrical Engineering Department of Electrical Engineering College of Engineering College of Engineering Salman Salman bin bin Abdulaziz Abdulaziz University University Al Al - - Kharj Kharj , Saudi Arabia , Saudi Arabia Data Movement Instructions Data Movement Instructions in Microprocessor in Microprocessor 8086/8088 8086/8088

Data Movement Instructions in Microprocessor …. Fayez F. M. El-Sousy Data Movement Instructions in Microprocessor 8086/8088 These instructions are used to transfer data from source

Embed Size (px)

Citation preview

Prof. Fayez F. M. El-Sousy

Prof. Fayez F. M. ElProf. Fayez F. M. El--SousySousy

Department of Electrical EngineeringDepartment of Electrical Engineering

College of EngineeringCollege of Engineering

SalmanSalman bin bin AbdulazizAbdulaziz UniversityUniversity

AlAl--KharjKharj, Saudi Arabia, Saudi Arabia

Data Movement InstructionsData Movement Instructions

in Microprocessor in Microprocessor

8086/80888086/8088

Prof. Fayez F. M. El-Sousy

Objectives of Data Movement Objectives of Data Movement

InstructionsInstructions in Microprocessor 8086/8088in Microprocessor 8086/8088

Upon completion of this chapter, you will be able to:Upon completion of this chapter, you will be able to:

�� Explain the operation of each data movement Explain the operation of each data movement

instruction with applicable addressing modes.instruction with applicable addressing modes.

�� Select the appropriate assembly language Select the appropriate assembly language

instruction to accomplish a specific data instruction to accomplish a specific data

movement task.movement task.

Prof. Fayez F. M. El-Sousy

Data Movement Instructions in Data Movement Instructions in

Microprocessor 8086/8088Microprocessor 8086/8088

�� These instructions are used to transfer These instructions are used to transfer

data from source to destination.data from source to destination.

�� The operand can be a constant, memory The operand can be a constant, memory

location, register or I/O port address.location, register or I/O port address.

8-bit 8-bit 8-bit

OP CODE OPERAND

1 byte 1 to 2 byte

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

MOVMOV

�� MOV Des, MOV Des, SrcSrc�� SrcSrc operand can be register, memory location or operand can be register, memory location or

immediate operand.immediate operand.

�� DesDes can be register or memory operand.can be register or memory operand.

�� Both Both SrcSrc and and DesDes cannot be memory location at cannot be memory location at

the same time.the same time.

�� Example:Example:

MOV CX, 037AHMOV CX, 037AH

MOV AL, BLMOV AL, BL

MOV BX, [0301H]MOV BX, [0301H]

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

MOVMOV

�� MOV Des, MOV Des, SrcSrc�� Example: Example: DS=ACDEH, SI=0724HDS=ACDEH, SI=0724H

MOV AX, [SI]MOV AX, [SI]

0727H

0726H

0725H

0724H

0723H

0722H

072CH

072BH

072AH

0729H

0728H

AD5F4H

AD5F3H

AD5F2H

AD5FCH

AD5FBH

AD5FAH

AD5F9H

AD5F8H

AD5F7H

AD5F6H

AD5F5H

02H

18H

A3H

7EH

69H

AAH

2EH

00H

55H

11H

72H

� Physical Address Physical Address

= ACEDx10H + 0724H= ACEDx10H + 0724H

= AD5F4H, AD5F5H= AD5F4H, AD5F5H

��AX=5502HAX=5502H

55 02

AH AL

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

PUSH and POPPUSH and POP

PUSH and POP InstructionsPUSH and POP Instructions

�� Both are important to store and retrieve data Both are important to store and retrieve data

from the LIFO structure (stack).from the LIFO structure (stack).

�� PUSH OperandPUSH Operand

�� It pushes the operand into top of stack.It pushes the operand into top of stack.

�� Example:Example:

PUSH BXPUSH BX

�� POP DesPOP Des

�� It pops the operand from top of stack to Des.It pops the operand from top of stack to Des.

�� Example:Example:

POP AXPOP AX

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

PUSHPUSH

PUSH: PUSH:

��In 8088 and 8086 PUSH always transfer 2 In 8088 and 8086 PUSH always transfer 2 bytes of data to the stack.bytes of data to the stack.

��It has the following syntax:It has the following syntax:

PUSH PUSH srcsrc

��SrcSrc could be any 2 byte register or memory could be any 2 byte register or memory location or immediate value.location or immediate value.

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

PUSHPUSH

How does PUSH executes?How does PUSH executes?

��Simply when we push 2 bytes of data to Simply when we push 2 bytes of data to the stack, the most significant byte is the stack, the most significant byte is stored in stack segment pointed to by SPstored in stack segment pointed to by SP--1, 1, and the least significant to location pointed and the least significant to location pointed by SPby SP--2, see the following example 2, see the following example

Example:Example:

Let AX=31F2H, SP=100H, SS=2000H, Let AX=31F2H, SP=100H, SS=2000H,

CX=FFFFH, BX=413AHCX=FFFFH, BX=413AH

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

PUSHPUSH

PUSH AXPUSH AX

31 F2

AX31

F2

Most Significant ByteMost Significant Byte

Least Significant ByteLeast Significant Byte

SS:SP =2000:0100H

SS:SP-1 =2000:00FFH

SS:SP-2 =2000:00FEH

SS:[SPSS:[SP--1] 1] ←←←←←←←← AH, 1st(most significant) byte.AH, 1st(most significant) byte.

SS:[SPSS:[SP--2] 2] ←←←←←←←← AL, 2nd(least significant) byte. AL, 2nd(least significant) byte.

After PUSH operation, SP After PUSH operation, SP ←←←←←←←← SP SP -- 22

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

PUSHPUSH

The effect of the PUSH AX instruction on SP and stack The effect of the PUSH AX instruction on SP and stack

memory locations 37FFH and 37FEH. AX=6AB3Hmemory locations 37FFH and 37FEH. AX=6AB3H

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

POPPOP

How does POP executes?How does POP executes?

��POPPOP : performs the inverse operation of PUSH: performs the inverse operation of PUSH

��POPPOP : removes data from stack and place it into : removes data from stack and place it into

target 16target 16--bit register.bit register.

POP BX POP BX

��BL BL ←←←←←←←← SS:[SP]SS:[SP]

��BH BH ←←←←←←←← SS:[SP+1]SS:[SP+1]

��after POP operation, SPafter POP operation, SP←←←←←←←← SP+2SP+2

POP CSPOP CS ; is not a valid instruction; is not a valid instruction

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

POPPOP

POP BXPOP BX

DF 54

BX

54

DF

Most Significant ByteMost Significant Byte

Least Significant ByteLeast Significant Byte

SS:SP =3000:0100H

SS:SP+1 =3000:0101H

SS:SP+2 =3000:0102H

BL BL ←←←←←←←← SS:[SP]SS:[SP]

BH BH ←←←←←←←← SS:[SP+1]SS:[SP+1]

After POP operation, SP After POP operation, SP ←←←←←←←← SP + 2SP + 2

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

POPPOP

Example:Example:

Let BX=DF54H, SP=100H, SS=3000HLet BX=DF54H, SP=100H, SS=3000H

POP BXPOP BX

BL=54 H at SP=0100HBL=54 H at SP=0100H

BH=DF at SP+1=0101HBH=DF at SP+1=0101H

After POP operation, SPAfter POP operation, SP←←←←←←←← SP+2=0102HSP+2=0102H

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

POPPOP

The POP BX instruction, showing how data are removed The POP BX instruction, showing how data are removed

from the stack. POP BXfrom the stack. POP BX

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

PUSHPUSH

Example:Example:

Let Let

AX=31F2HAX=31F2H

SP=072AHSP=072AH

SS=SS=ACEDACEDHH

CX=FF67HCX=FF67H

BX=413AHBX=413AH

PUSH AXPUSH AX

PUSH BXPUSH BX

PUSH CX PUSH CX

SS:SP =ACED:072A

SS:SP-1 =ACED:0729

SS:SP-2 =ACED:0728

CHCH CLCL

6767FFFF

3131 F2F2

AHAH ALAL

4141 3A3A

BHBH BLBL

SS:SP-5 =ACED:0725

SS:SP-4 =ACED:0726

SS:SP-3 =ACED:0727

SS:SP-6 =ACED:0724

Solution:Solution:

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

PUSHPUSH

0727H

0726H

0725H

0724H

0723H

0722H

072CH

072BH

072AH

0729H

0728H

AD5F4H

AD5F3H

AD5F2H

AD5FCH

AD5FBH

AD5FAH

AD5F9H

AD5F8H

AD5F7H

AD5F6H

AD5F5H

02H

18H

A3H

7EH

69H

AAH

2EH

00H

55H

11H

72H

beforebefore

0727H

0726H

0725H

0724H

0723H

0722H

072CH

072BH

072AH

0729H

0728H

AD5F4H

AD5F3H

AD5F2H

AD5FCH

AD5FBH

AD5FAH

AD5F9H

AD5F8H

AD5F7H

AD5F6H

AD5F5H

67H

18H

A3H

7EH

31H

F2H

41H

3AH

FFH

11H

72H

afterafter

StackStack StackStack

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

PUSH BXPUSH BX

•• The highThe high--order 8 bits are placed in the location addressed by SP order 8 bits are placed in the location addressed by SP –– 11

•• The lowThe low--order 8 bits are placed in the location addressed by SP order 8 bits are placed in the location addressed by SP –– 22

•• After the data are stored by a PUSH, the contents of the SP regAfter the data are stored by a PUSH, the contents of the SP registerister

decrement by twodecrement by two

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

POPPOP

Example:Example:

Let Let

SP=0724HSP=0724H

SS=SS=ACEDACEDHH

POP CXPOP CX

POP BXPOP BX

POP AX POP AX

SS:SP+5 =ACED:0729

SS:SP+4 =ACED:0728

CHCH CLCL

6767FFFF

3131 F2F2

AHAH ALAL

4141 3A3A

BHBH BLBL

SS:SP+1 =ACED:0725

SS:SP+2 =ACED:0726

SS:SP+3 =ACED:0727

SS:SP =ACED:0724

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

POPPOP

0727H

0726H

0725H

0724H

0723H

0722H

072CH

072BH

072AH

0729H

0728H

AD5F4H

AD5F3H

AD5F2H

AD5FCH

AD5FBH

AD5FAH

AD5F9H

AD5F8H

AD5F7H

AD5F6H

AD5F5H

67H

18H

A3H

7EH

31H

F2H

41H

3AH

FFH

11H

72H

StackStackSS:SP+5 =ACED:0729

SS:SP+4 =ACED:0728

CHCH CLCL

6767FFFF

3131 F2F2

AHAH ALAL

4141 3A3A

BHBH BLBL

SS:SP+1 =ACED:0725

SS:SP+2 =ACED:0726

SS:SP+3 =ACED:0727

SS:SP =ACED:0724

Solution:Solution:

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

POP CXPOP CX

•• The lowThe low--order 8 bits are removed from the location addressed by SP.order 8 bits are removed from the location addressed by SP.

•• The highThe high--order 8 bits are removed from the location addressed by order 8 bits are removed from the location addressed by

SP+1SP+1

•• The SP register is incremented by 2The SP register is incremented by 2

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

LEALEA

�� LoadLoad--Effective Address (LEA)Effective Address (LEA)

�� LEALEA stands for load effective addressstands for load effective address..

LEA Register, LEA Register, SrcSrc

�� It loads a 16It loads a 16--bit register with the offset address bit register with the offset address

of the data specified by the of the data specified by the SrcSrc..

LEA AX, NUMBLEA AX, NUMB

�� AX AX ←←←←←←←← operand offset address MUMBoperand offset address MUMB

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

LEALEA

�� Example:Example:

LEA BX, [DI]LEA BX, [DI] ;; loads offset address loads offset address

specified by [DI]specified by [DI] (contents(contents

of DI) into BX registerof DI) into BX register

MOV BX, [DI] ; MOV BX, [DI] ; loads the data stored at loads the data stored at

the memory locatithe memory location on

addressed by [DI]addressed by [DI] into BXinto BX

registerregister

MOV BX, DIMOV BX, DI

= LEA BX, [DI]= LEA BX, [DI]

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

LEALEA

MOV BX, DIMOV BX, DI performs in less time and is often performs in less time and is often

preferred topreferred to LEA BX, [DI]LEA BX, [DI]

�� Example:Example:

LEA SI, [BX+DI] LEA SI, [BX+DI]

If BX = 1000H, DI = 2000If BX = 1000H, DI = 2000

�� Solution:Solution:

SI=BX+DISI=BX+DI

=1000+2000=3000H (16=1000+2000=3000H (16--bit offset bit offset

address)address)

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

LEALEA

The sum generated by this instructionThe sum generated by this instruction

LEA SI, [BX+DI]LEA SI, [BX+DI]

is a modulois a modulo--64K sum drops any carry out of the 64K sum drops any carry out of the

1616--bit resultbit result

�� Example:Example:

LEA SI, [BX+DI]LEA SI, [BX+DI]

If If BX = 1000H, DI = FF00H, SI = 0F00HBX = 1000H, DI = FF00H, SI = 0F00H

�� Solution:Solution:

SI=BX+DISI=BX+DI

=1000+FF00=0F00 H =1000+FF00=0F00 H instead ofinstead of 10F00H10F00H

Prof. Fayez F. M. El-Sousy

�� LDS Des, LDS Des, SrcSrc�� It loads 32It loads 32--bit pointer from memory source to bit pointer from memory source to

destination register and DS.destination register and DS.

�� The offset is placed in the destination register The offset is placed in the destination register

and the segment is placed in DS.and the segment is placed in DS.

�� To use this instruction the word at the lower To use this instruction the word at the lower

memory address must contain the offset and the memory address must contain the offset and the

word at the higher address must contain the word at the higher address must contain the

segment.segment.

Data Movement InstructionsData Movement Instructions

LDSLDS

Prof. Fayez F. M. El-Sousy

�� LDS Des, LDS Des, SrcSrc� Example:Example:

LDS BX, [DI]LDS BX, [DI]

�� If DS=If DS= 1000H, DI = 1000H1000H, DI = 1000H

�� The The LDS BX, [DI]LDS BX, [DI] instruction loads register BX instruction loads register BX

from addresses 11000H and 11001H and register from addresses 11000H and 11001H and register

DS from locations 11002H and 11003H. This DS from locations 11002H and 11003H. This

instruction is shown at the point just before DS instruction is shown at the point just before DS

changes to 3000H and BX changes to 127AH.changes to 3000H and BX changes to 127AH.

Data Movement InstructionsData Movement Instructions

LDSLDS

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

LDSLDS

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

LESLES

�� LES Des, LES Des, SrcSrc�� It loads 32It loads 32--bit pointer from memory source to bit pointer from memory source to

destination register and ES.destination register and ES.

�� The offset is placed in the destination register The offset is placed in the destination register

and the segment is placed in ES.and the segment is placed in ES.

�� To use this instruction the word at the lower To use this instruction the word at the lower

memory address must contain the offset and the memory address must contain the offset and the

word at the higher address must contain the word at the higher address must contain the

segment.segment.

�� This instruction is very similar to LDS except This instruction is very similar to LDS except

that it initializes ES instead of DS.that it initializes ES instead of DS.

Prof. Fayez F. M. El-Sousy

�� LES Des, LES Des, SrcSrc� Example:Example:

LES BX, [DI]LES BX, [DI]

�� If ES=If ES= 1000H, DI = 1000H1000H, DI = 1000H

�� The The LES BX, [DI]LES BX, [DI] instruction loads register instruction loads register BXBX

from addresses from addresses 11000H and 11001H11000H and 11001H and register and register

ESES from locations from locations 11002H and 11003H11002H and 11003H. This . This

instruction is shown at the point just before ES instruction is shown at the point just before ES

changes to 3000H and BX changes to 127AH.changes to 3000H and BX changes to 127AH.

Data Movement InstructionsData Movement Instructions

LESLES

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

LESLES

Prof. Fayez F. M. El-Sousy

�� LAHF:LAHF:

�� It transfer the lower byte of flag register to AH.It transfer the lower byte of flag register to AH.AH AH ←←←←←←←← FLAG (Lower 8FLAG (Lower 8--bit)bit)

�� SAHF:SAHF:

�� It transfer the contents of AH to lower byte of It transfer the contents of AH to lower byte of

flag register.flag register.FLAG (Lower 8FLAG (Lower 8--bit) bit) ←←←←←←←← AHAH

�� PUSHF:PUSHF:

�� Pushes flag register to top of stack. Pushes flag register to top of stack.

�� POPF:POPF:

�� Pops the stack top to flag register.Pops the stack top to flag register.

Data Movement InstructionsData Movement Instructions

LAHF, SAHF, PUSHF, POPFLAHF, SAHF, PUSHF, POPF

Prof. Fayez F. M. El-Sousy

XCHG Des, XCHG Des, SrcSrc�� This instruction exchanges This instruction exchanges SrcSrc with Des.with Des.

�� It Exchanges contents of a register with any other It Exchanges contents of a register with any other

register or memory location.register or memory location.

�� It It can notcan not exchange exchange segment registerssegment registers..

�� It It can notcan not exchange exchange two memory locationstwo memory locations directly.directly.

�� Use any addressing mode except immediate.Use any addressing mode except immediate.

�� Example:Example:

XCHG DX, AXXCHG DX, AX

DX= 3000H, AX = 1000HDX= 3000H, AX = 1000H

�� After Execution this InstructionAfter Execution this Instruction

DX= 1000H, AX = 3000HDX= 1000H, AX = 3000H

Data Movement InstructionsData Movement Instructions

XCHGXCHG

Prof. Fayez F. M. El-Sousy

Example:Example:

XCHG DX, AXXCHG DX, AX

XCHG AL, CLXCHG AL, CL

XCHG CX, BPXCHG CX, BP

XCHG DX, SIXCHG DX, SI

XCHG AL, [DI]XCHG AL, [DI]

Data Movement InstructionsData Movement Instructions

XCHGXCHG

Prof. Fayez F. M. El-Sousy

XLATXLAT�� This instruction Converts the contents of the This instruction Converts the contents of the ALAL

register into a number stored in a memory table.register into a number stored in a memory table.

�� It performs the direct table lookup technique often It performs the direct table lookup technique often

used to convert one code to another.used to convert one code to another.

�� An An XLATXLAT instruction first adds the contents of instruction first adds the contents of ALAL to to

BXBX to form a memory address within the data segment.to form a memory address within the data segment.

�� It copies the contents of this address into It copies the contents of this address into ALAL..

�� It is only instruction that adds an 8It is only instruction that adds an 8--bit to a 16bit to a 16--bit bit

numbernumber

�� Example:Example:

AL AL ←←←←←←←← DS:[BX + AL]DS:[BX + AL]

Data Movement InstructionsData Movement Instructions

XLAT (Translate)XLAT (Translate)

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

XLAT (Translate)XLAT (Translate)

The operation of the XLAT instruction at the point just before The operation of the XLAT instruction at the point just before

6DH is loaded into AL.6DH is loaded into AL.

Prof. Fayez F. M. El-Sousy

�� IN Accumulator, Port AddressIN Accumulator, Port Address�� This instruction transfers the operand from specified This instruction transfers the operand from specified

port to accumulator register.port to accumulator register.

IN AX, 0028 HIN AX, 0028 H�� An IN instruction transfers data from an external I/O An IN instruction transfers data from an external I/O

device into AL or AXdevice into AL or AX

�� OUT Port Address, AccumulatorOUT Port Address, Accumulator�� This instruction transfers the operand from accumulator This instruction transfers the operand from accumulator

to specified port.to specified port.

OUT 0028 H, AXOUT 0028 H, AX�� An OUT transfers data from AL or AX to an external An OUT transfers data from AL or AX to an external

I/O device.I/O device.

Data Movement InstructionsData Movement Instructions

IN and OUTIN and OUT

Prof. Fayez F. M. El-Sousy

�� IN & OUT instructions perform I/O operations.IN & OUT instructions perform I/O operations.

�� Contents of AL or AX are transferred only Contents of AL or AX are transferred only

between I/O device and microprocessor.between I/O device and microprocessor.

�� Two forms of I/O device (port) addressing:Two forms of I/O device (port) addressing:

�� FixedFixed--port addressingport addressing allows data transfer allows data transfer

between AL, or AX using an 8between AL, or AX using an 8--bit I/O port bit I/O port

address. address.

�� Port number follows the instructionPort number follows the instruction’’s s opcodeopcode..

IN AX, 0028 HIN AX, 0028 H

OUT 0028 H, AXOUT 0028 H, AX

Data Movement InstructionsData Movement Instructions

IN and OUTIN and OUT

Prof. Fayez F. M. El-Sousy

�� VariableVariable--port addressingport addressing allows data transfers allows data transfers

between AL or AX and a 16between AL or AX and a 16--bit port address. bit port address.

�� The I/O port number is stored in register DX, The I/O port number is stored in register DX,

which can be changed (varied) during the which can be changed (varied) during the

execution of a program.execution of a program.

MOV DX, 0028HMOV DX, 0028H

IN AX, DXIN AX, DX

OUT DX, AXOUT DX, AX

Data Movement InstructionsData Movement Instructions

IN and OUTIN and OUT

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

IN and OUTIN and OUT

The signals found in the microprocessorThe signals found in the microprocessor--based system for an OUT based system for an OUT

19H, AX instruction.19H, AX instruction.

Prof. Fayez F. M. El-Sousy

Data Movement InstructionsData Movement Instructions

IN and OUTIN and OUT