lecture 6 string operations

23
Lecture 6 String Operations Modified and Presented By Dr. Rajesh Palit Asst. Professor, EECS, NSU Originally Prepared By Dr. Shazzad Hosain, EECS, NSU

Upload: fonda

Post on 15-Feb-2016

32 views

Category:

Documents


0 download

DESCRIPTION

Lecture 6 String Operations. Modified and Presented By Dr. Rajesh Palit Asst. Professor, EECS, NSU Originally Prepared By Dr. Shazzad Hosain , EECS, NSU. Agenda. String Data Transfer Instructions The Direction Flag LODS Instructions STOS Instructions MOVS Instructions - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lecture  6 String Operations

Lecture 6

String Operations

Modified and Presented ByDr. Rajesh Palit

Asst. Professor, EECS, NSUOriginally Prepared By

Dr. Shazzad Hosain, EECS, NSU

Page 2: Lecture  6 String Operations

Agenda

• String Data Transfer Instructions– The Direction Flag– LODS Instructions– STOS Instructions– MOVS Instructions– INS and OUTS Instructions

• More Examples

Page 3: Lecture  6 String Operations

String Data Transfers

• Five Instructions– LODS, STOS, MOVS, INS and OUTS

• Each instruction allows data transfer either a single byte, word or double word

Page 4: Lecture  6 String Operations

The Direction Flag, DF• DF = 0, auto-increment mode of SI, DI• DF = 1, auto-decrement mode of SI, DI• CLD instruction clears the D flag (D = 0)• STD instruction sets the D flag (D = 1)• SI (Source Index) points to DS (Data Segment) i.e. DS:[SI]• DI (Destination Index) points to ES (Extra Segment) i.e. ES:[DI]

Page 5: Lecture  6 String Operations

LODS Instructions

• LODS instructions loads AL, AX or EAX with data indexed by SI register

• LODSB – load string byte

Table 4-10: from Brey’s book

Page 6: Lecture  6 String Operations

Example

STRING1 DB ‘ABC’

MOV AX, @DATAMOV DS, AXLEA SI, STRING1CLDLODSBLODSB

Page 7: Lecture  6 String Operations

STOS Instructions

• STOS instructions stores data form AL, AX or EAX to memory indexed by DI register

• STOSB – store string byte

Table 4-11: from Brey’s book

Page 8: Lecture  6 String Operations

Example

STRING1 DB ‘HELLO’

MOV AX, @DATAMOV ES, AXLEA DI, STRING1CLDMOV AL, ‘A’STOSBSTOSB

Page 9: Lecture  6 String Operations

REP (Repeat Prefix))

• REP is used to execute string instructions repeatedly by CX times.

• REP automatically decrements CX by 1 • REP works for any string instructions except

LODS instruction

Page 10: Lecture  6 String Operations

Example : Clear the video text display1 2 3 80****

12

25

***

543210

a b c

07H

07H

07H

Video display

Text memory

c

b

a

20H

20H

20H B800H

Example 4-5: From Brey’s Book

Page 11: Lecture  6 String Operations

MOVS Instructions

• MOVSB – move string byte from one memory location to other

Table 4-13 : From Brey’s Book

Page 12: Lecture  6 String Operations

Example

.DATASTRING1 DB ‘HELLO’STRING1 DB 5 DUP (?)

MOV AX, @DATAMOV DS, AXMOV ES, AX

LEA SI, STRING1LEA DI, STRING2CLDMOVSBMOVSB

Page 13: Lecture  6 String Operations

Example: Scroll Up One Line1 2 3 80****

12

25

***

543210

Video display

Text memoryB800H

Example 4-6: From Brey’s Book

160**

**SI

DI

Page 14: Lecture  6 String Operations

INS Instructions

• INSB – Input String Byte, from I/O device to memory location

Table 4-14: From Brey’s Book

Page 15: Lecture  6 String Operations

Example• Read 50 bytes of data from an I/O device whose address in

03ACH and store the data in LISTS array

Example 4-7: From Brey’s Book

Page 16: Lecture  6 String Operations

OUTS Instructions

• OUTSB – Output String Byte, from string memory location to I/O device

Table 4-15: From Brey’s Book

Page 17: Lecture  6 String Operations

Example

• Transfer data form memory array (ARRAY) to an I/O device at I/O address 3ACH

Example 4-8: From Brey’s Book

Page 18: Lecture  6 String Operations

Agenda

• String Data Transfer Instructions– The Direction Flag– LODS Instructions– STOS Instructions– MOVS Instructions– INS and OUTS Instructions

• More Examples

Page 19: Lecture  6 String Operations

Concatenate Two Input StringsThen Display

Input String 1:Hello

Input String 2:World!

Concatenated String:Hello World!

Display message 1

Read first string

Display message 2

Read second string

Concatenate the two strings

Display the result

Page 20: Lecture  6 String Operations

Display message 1Read first stringDisplay message 2Read second stringConcatenate the two stringsDisplay the result

Display message 1Read first string

Page 21: Lecture  6 String Operations

Display message 1Read first stringDisplay message 2Read second stringConcatenate the two stringsDisplay the result

Display message 2Read second string

Page 22: Lecture  6 String Operations

Display message 1Read first stringDisplay message 2Read second stringConcatenate the two stringsDisplay the result

Concatenate the two stringsDisplay the result

Page 23: Lecture  6 String Operations

References

• Ch 11, Assembly Language Programming – by Charles Marut

• Section 4-4, Intel Microprocessors – by Brey