data movement instructions - wordpress.com · movs instruction transfers a byte or, word from the...

14
Data Movement Instructions Dr. Sikder Sunbeam Islam Associate Professor Dept. of EEE, IIUC

Upload: others

Post on 19-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

Data Movement

Instructions Dr. Sikder Sunbeam Islam

Associate Professor

Dept. of EEE, IIUC

Page 2: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

IN and OUT Instructions

IN and OUT instruction performs I/O operation..

An IN instruction transfers data from an external I/O device into AL or AX;

an OUT transfer data from AL or AX to an external I/O device.

Example: IN AL, 89H ; 8 bits are input to AL from I/O port 89H (fixed port addressing)

IN AL, DX ; 8 bits are input to AL from I/O port DX (variable port addressing)

OUT 89H, AX ; 16-bits are output to I/O port 89H from AX (fixed port addressing)

OUT DX, AL; 8-bit data are output to I/O port DX from AL (variable port addressing)

Page 3: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

PUSH instructions

PUSH instruction always transfers two byte of data to the stack (16 bit

processor).

Example: PUSH AX

SS:[SP-1]=AH

SS:[SP-2]=AL

SP=Stack pointer

SS=Stack segment

Page 4: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

PUSH instructions

(Cont.)

PUSHA; (Push all)—copies the content of the

internal register set ( following order AX,CX,DX,

BX,SP,BP,SI and DI ), except segment registers to

stack.

PUSH ‘A’; pushes 0041 H (ASCII code of ‘A’) to

stack.

PUSHF; (Push all)—copies the content of the Flag

register to stack.

PUSH BX, the first byte of data copied to stack

(memory location addressed by SP in the stack

segment) .

Page 5: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

POP instructions

POP instruction performs the inverse operation of a PUSH instruction.

POP BX; the first byte of data removed from stack (memory location addressed by SP in the stack segment) into register BL.

POPA; (POP all), removes 16 bytes of data from stack and places them into the following registers, in the order: DI, SI, BP, SP, BX, DX, CX and AX

POPF; reverse of PUSHF.

POPCS; not valid

POP 1000H; not valid.

Page 6: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

Load-effective Address

LEA (Load Effective Address)

It loads a 16-biit register with the offset address of the data specified by the source.

Example: LEA BX, [DI] ; BX ←operand offset address [DI], not the contents of address [DI].

By comparing LEA with MOV, we observe that LEA BX, [DI] loads the offset address specified by [DI] (content of DI) into BX register; MOV BX, [DI] loads the data stored at the memory location addressed by [DI] into register BX. i.e. (MOV BX, DI= LEA BX, [DI])

LDS (Load DS)

The offset is placed in the destination register and the segment is placed in DS.

Example: LDS BX, [DI]; If DS= 1000H, DI = 1000H; The LDS BX, [DI] instruction loads register BX from addresses 11000H and 11001H and register DS from locations 11002H and 11003H.

LES (Load ES)

Example: LES BX, [DI] ; Loads ES and BX with 32-bit content of data segment memory location [DI]

Page 7: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

Operation of LDS BX, [DI] instruction

Page 8: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

String Data transfer

LODS (Load string) ; instruction loads AL or AX with data stored at the data

segment offset address index by the SI register.

It loads contents of memory pointed by DS:[SI] into AL or AX.

After loading AL with a byte or, AX with a word, the content of SI increment, if

D=0; or decrement if D=1.

LODSB (loads a byte) instruction causes a byte to be loaded into AL.

LODSB ; AL=DS: [SI] ; SI=SI+1 (if D=0) or SI=SI-1 (if D=1)

LODSW (loads a word) instruction causes a word to be loaded into AX.

LODSW ; AX=DS:[SI]; SI=SI+2 (if D=0) or, SI=SI-2(if D=1)

Page 9: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

String Data Transfer (Contin.)

STOS (Store string) instruction stores AL or, AX at the extra segment memory

location addressed by the DI register. (i.e. The content of AL or AX stored to

memory pointed by ES:[DI])

STOSB (stores a byte) instruction stores the byte in AL at the extra segment

memory location addressed by DI.

STOSW (stores a word) instruction stores AX in the extra segment memory

location addressed by DI.

Example: STOSB ; ES:[DI]=AL ; DI=DI+1 (if D=0), DI=DI-1 (if D=1)

STOSW ; ES:[DI]=AX ; DI=DI+2 (if D=0), DI=DI-2 (if D=1)

Page 10: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

String Data Transfer : MOVS

MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by DI.

This is only memory-to-memory transfer allowed in the 8086 microprocessor.

As with the other string instructions, addresses are incremented or decremented checking the status of direction flag.

Examples: MOVSB ; ES:[DI]=DS:[SI], DI=DI±1, SI=SI±1 (byte transferred)

MOVSW ; ES:[DI]=DS:[SI], DI=DI±2, SI=SI±2 (word transferred)

EXAMPLE: MOVS WORD;

If [DF]=0, [DS]=3000H, [SI]=0020H, [ES]=5000H, [DI]=0040H, [30020]=30H, [30021]=05H, [50040]=06H, [50041]=20H.

After MOVS WORD, [50040]=30H, [50041]=05H, [SI]=0021H, [DI]=0041H.

Page 11: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

XCHG and XLAT

XCHG Src., Des.; This instruction exchanges Src. with Des.

It Exchanges contents of a register with any other register or memory location.

It can not exchange segment registers.

It can not exchange two memory locations directly.

Use any addressing mode except immediate.

Example:

XCHG DX, AX

DX= 3000H, AX = 1000H ; After Execution this Instruction

DX= 1000H,, AX = 3000H

Page 12: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

XLAT (Translate)

XLAT (translate) instruction converts of the AL register into a number stored in a memory table.

XLAT instruction first adds the contents of AL to BX to form a memory address within the data segment.

It copies the contents of this address into AL.

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

Example:

AL ←DS:[BX + AL]

Example:

Page 13: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

Exercise:

Q. An assembly language program with a portion of memory location of Data Segment

and Extra Segment are given below. Also initial content of different registers

are given. Find the content of AX, BX, CX and DX after execution of instructions.

CLD

MOVSW

STOSB

MOV BL, AL

LODSW

MOV DH, AL

MOV CL, AH

XCHG BX, CX

2007

2006

2005

2004

2003

2002

2001

2000

21

12

Data

Segment

200A

2009

20082007

2006

2005

2004

2003

2002

2001

2000

32

F5

Extra

Segment

200A

2009

200877

88

20

07

99

00

91

66

55

78

10

87

60

A2

F3

21

CD

1C

11A0

4455

AX

BX

CX

DX

1234

6213

F000

4000

DS

ES

SI

DI

2000

2003

Page 14: Data Movement Instructions - WordPress.com · MOVS instruction transfers a byte or, word from the data segment location addressed by SI to the extra segment location addressed by

References

Microprocessor and Interfacing Programming and Hardware; Douglas V Hall, 2nd

Edition.

Microprocessors and Microcomputer-Based System Design; Mohammed

Rafiquzzaman, Revised edition.

Microprocessor & Interfacing Lecture Materials ;Mohammed Abdul kader, IIUC.

The Intel Microprocessor; B.B. Brey, Seventh Edition.

Data Movement Instruction in 8086 Microprocessor, Prof. Fayez F.M.El-Sousy; Sallman

biin Abdullaziiz Uniiversiity, Saudi Arabia