Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction...

17
Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] • String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions • Few Examples

Transcript of Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction...

Page 1: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

Topic – string – Ch. 11 [Marut] Ch. 4 [Brey]

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

• Few Examples

Page 2: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

String Data Transfers

• 8086 – string a byte or word array • What is array?• Need – register indirect addressing mode• Allow mem2mem operations• Five Instructions– LODS, STOS, MOVS, INS and OUTS

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

Page 3: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

Flags - recap

• 6 status flags

• 3 control flags – to control Processor’s ops.Direction flag [DF]: to determine the direction

in which string operations will proceed. By 2 index registers – Si and DI

Page 4: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

Recap – ch. 3write on board

• SP, BP, SI and DI – point to [contain the offset addresses of] mem locations.

• SP – stack pointer • BP – base pointer • SI – source index register is used to point to mem

locations in the data segment addressed by DS [DS is one of the Segment registers – CS-code/DS-data/SS-stack/ES-extra segment]

• DI – Destination index – same as DI. Esp. for string ops that use DI to access memory locations addressed by ES.

Page 5: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

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) – clears direction flag• STD instruction sets the D flag (D = 1) – sets DF• CLD, STD have no effect on other flags

• 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 6: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

LODS Instructions• LODS instructions loads AL [with a Byte], AX [with a Word] or EAX

[with a Boubleword] with data indexed by SI register [EAX for 80386/+]

• LODSB – load string byte• LODSW – load string doubleword

Table 4-10: from Brey’s book

Page 7: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

Example

STRING1 DB ‘ABC’

MOV AX, @DATAMOV DS, AXLEA SI, STRING1CLDLODSBLODSB

Read

Page 8: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

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 9: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

Example

STRING1 DB ‘HELLO’

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

Read

Page 10: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

MOVS Instructions

• MOVS – move string from one memory location to other

Table 4-13 : From Brey’s Book

Page 11: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

Example

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

MOV AX, @DATAMOV DS, AXMOV ES, AX

LEA SI, STRING1LEA DI, STRING2CLDMOVSBMOVSB

Read

Page 12: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

Agenda

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

• More Examples Read

Page 13: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

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 14: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

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

Display message 1Read first string

Page 15: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

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

Display message 2Read second string

Page 16: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

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

Concatenate the two stringsDisplay the result

Page 17: Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.

References

materials are from Dr. Sazzad, NSU• Ch 11, Assembly Language Programming – by Charls

Marut• Section 4-4, Intel Microprocessors – by Brey