String Instructions in 8086 Assembly Language: Processing Byte and Word Arrays, High school final essays of Mathematics

An overview of string instructions in 8086 assembly language. String instructions are designed for array processing, including copying, searching, storing, and comparing strings of characters. the use of the DUP operator for declaring large arrays, the syntax for string operations, and the role of the direction flag (DF) and index registers SI and DI. String instructions include MOVSB, MOVSW, MOVSD, STOSB, STOSW, STOSD, LODSB, LODSW, LODSD, SCASB, SCASW, SCASD, CMPSB, CMPSW, and CMPSD.

Typology: High school final essays

2020/2021

Uploaded on 11/13/2021

sanjana-kirshan
sanjana-kirshan 🇵🇰

1 document

1 / 31

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
String Instruction
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f

Partial preview of the text

Download String Instructions in 8086 Assembly Language: Processing Byte and Word Arrays and more High school final essays Mathematics in PDF only on Docsity!

String Instruction

Overview

  • In this chapter we consider a special group of

Instructions called the string instruction.

  • In 8086 assembly language, a memory string or string ls

simply a byte or word array.

  • Thus, string Instructions are designed for array

processing:

  • The tasks carried out by the string instructions can be

performed by using the register indirect addressing

mode ,

  • the string Instructions have some built-in advantages.

For example, they provide automatic updating of pointer

registers and allow memory to memory operations...

String

  • String instruction process with array. - DUP instruction: if you need to declare a large array you can

use DUP operator.

  • The syntax for DUP :

number DUP ( value(s) )

  • number - number of duplicate to make (any constant value).

value - expression that DUP will duplicate.

for example:

c DB 5 DUP(9)

String operation

Move string Store string Load string Scan string Compare string

MOVSB STOSB LODSB SCASB CMPSB

MOVSW STOSW LODSW SCASW CMPSW

MOVSD STOSD LODSD SCASD CMPSD

Move string from one variable to another variable

Store the content of al register to a destination variable

Load a string from source to Al register ( Al register work here as a destination.

Compare contents of destination variable with content of Al register

Compare the contents of source variable to the contents of destination variable

How it will identify the first location in

destination to save string

  • Suppose that the following string has been

declared

- String db ‘ABCDE

Offset address Content ASCII
0200h 41h A
0201h 42h B
0202h 43h C
0203h 44h D
0204h 45h E

Cont.

• If DF = 0, SI and DI proceed in the direction of

increasing memory addresses: from left to

right across the string.

• Conversely, if DF = 1, SI and DI proceed in the

direction of decreasing memory addresses:

from right to left.

A B C D

Destination Source

DI SI

A B C D

  • IF DF=0 (DO increment automatically)
  • SI and DI proceed in the direction of increasing

memory addresses from left to right.

- DF = 0 => forward (left to right) processing

  • If DF=1 (DO decrement automatically)
  • SI and DI proceed in the direction of decreasing

memory addresses from right to left

- DF = 1 => backward (right to left) processing

Moving String

  • Movsb: move string byte (1 byte)

given by DS:SI into ES:DI

  • Movsw: move string word (2 byte)

given by DS:SI into ES:DI

  • Movsd: move string double word (4byte)

given by DS:SI into ES:DI

Note: the string instructions use DS:SI as the Source

string and ES:DI as the destination string. (For the string instructions, DI references an offset in the ES by default).

Before MOVSB

String 1 H E L L O

SI

offset

0 1 2 3 4

String 2

offset (^5 6 7 8 )

DI

After MOVSB

String 1 H E L L O

SI

offset

0 1 2 3 4

String 2 (^) H E

offset (^5 6 7 8 )

DI

Example

• .DATA

STRING1 DB 'HELLO'

STRING2 DB 5 DUP (0)

• .CODE

MOV AX, @DATA

MOV DS, AX ; init DS

MOV ES, AX ; init ES

• LEA SI, STRING1 ; source

LEA DI, STRING2 ; destination

CLD ; DF = 0

• MOVSB ; mov 1

st

byte

MOVSB ; mov 2

nd

byte

Reverse operation

• .DATA

STRING1 DB 'HELLO'

STRING2 DB 5 DUP (0)

• .CODE

MOV AX, @DATA

MOV DS, AX ; init DS

MOV ES, AX ; init ES

• LEA SI, STRING1+4 ; source

LEA DI, STRING2 ; destination

• mov cx, 5

std ; DF = 1

;right to left processing

• Rep movsb

Store string

• STOSB - copies contents of AL to BYTE

address given by ES:DI. DI is

incremented/decremented by 1.

STOSW - copies the contents of AX to the

WORD address given by ES:DI. DI is

incremented/decremented by 2.

STOSD - copies contents of EAX to the

DOUBLE WORD address given by ES:DI. DI is

incremented/decremented by 4.