0% found this document useful (0 votes)
21 views7 pages

LAB9

The document outlines a lab assignment for a Computer Architecture course focused on string manipulation using the emu8086 software tool. It explains the functionality of string instructions in the 8086 microprocessor, including operations like moving and storing strings, as well as the use of the Direction Flag. Additionally, it provides lab exercises that require writing assembly programs to manipulate strings and arrays.

Uploaded by

manavlund5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

LAB9

The document outlines a lab assignment for a Computer Architecture course focused on string manipulation using the emu8086 software tool. It explains the functionality of string instructions in the 8086 microprocessor, including operations like moving and storing strings, as well as the use of the Direction Flag. Additionally, it provides lab exercises that require writing assembly programs to manipulate strings and arrays.

Uploaded by

manavlund5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Sukkur Institute of Business Administration University

Department of Computer Systems Engineering


CSE-222: Computer Architecture and Organization, Spring 2025

Lab # 09:
To display and manipulate the strings using emu8086
software tool

Instructor: Dr Mumtaz Ali Kaloi

Submission Profile

Name: Submission Date:

Enrolment ID: Receiving Authority Name and Signature:

Comments: ______________________________________________________________________
Objectives

 To explain the working of string instructions using assembly language program.

Theory:
Read the details given below in order to comprehend the basic operations of string instructions
programming. Study in detail and become familiar with the various ways and in which these
modes can be used.

String
The 8086 microprocessor is equipped with special instructions to handle string operations. By string it
mean a series of data words or bytes that reside in consecutive memory locations. The string
instructions of the 8086 permit a programmer to implement operations such as to move data from one
block of memory to a block elsewhere in memory. A second type of operation that is easily performed
is to scan a string and data elements stored in memory looking for a specific value. Other examples are
to compare the elements and two strings together in order to determine whether they are the same or
different. In 8086 assembly language, a memory string or string is simply a byte or word array.

The Direction Flag

Its purpose is to determine the direction in which string operations will proceed. The FLAGS register
contains six status flags and three control flags. We know that the status flags reflect the result of an
operation that the processor has done. The control flags are used to control the processor’s operations.
String operations are implemented by index registers SI and DI.

For example,

STRING1 DB ‘ABCDE’

Suppose this string is stored in memory starting at offset 0200h then


 If DF = 0, SI and DI proceeds from left to right towards increasing address.
 If DF = 1, SI and DI proceeds from right to left towards decreasing address.

In the DEBUG display, DF= 0 is symbolized by UP, and DF= 1 by DN

CLD (Clear Direction Flag) instruction

To make DF = 0, use the CLD instruction

STD (Set Direction Flag) instruction

To make DF = 1, use the STD instruction

CLD and STD have no effect on Flags register.

Moving a String

Suppose we have defined two strings as follows:

.DATA
STRING1 DB “HELLO”
STRING2 DB 5 DUP (?)
And we want to move the contents of STRING1 (source string) into STRING2 (destination string).
This operation is needed for many string operations, such as duplication a string or concatenating
(attaching on string to the end of another string).

The MOVSB instruction

MOVSB ; move string byte

It copies the contents of the byte addressed by DS: SI, to the byte addressed by ES: DI. The contents of
the source byte are unchanged. After the byte has been moved, both SI and DI arc automatically
incremented If DF = 0, or decremented If DF= 1.

For example, to move the first two bytes of STRINGl to STRING2, we execute the following
Instructions:

MOV AX,@DATA
MOV DS, AX
MOV ES, AX
LEA SI, STRING1 ; SI points to source sting
LEA DI, STRING2 ; DI points to destination sting
CLD ; Clear DF
MOVSB ; move first byte
MOVSB ; move second byte

Figure 1: MOVSB Operation

REP prefix

MOVSB moves only a single byte from the source string to the destination string. To move the entire
string, first initialize CX to the number N of bytes in the source string and execute,

REP MOVSB

The REP prefix causes MOVSB to be executed N times. After each MOVSB, CX is decremented until
it becomes 0. For example, to copy STRING1 of the preceding section Into STRING2, we execute
CLD

LEA SI, STRING1

LEA DI,STRING2

MOV CX,5 ;no. of chars in STRING!

REP MOVSB

The MOVSW instruction

This is a word form of MOVSB.

MOVSW ; move string word

MOVSW moves a word from the source to the destination string. It expects DS: SI to point to a source
string word, and ES: DI to point to a destination string word. After the string word has been moved,
both SI and DI arc automatically incremented by 2 if DF = 0, or decremented by 2 if DF= 1.

Note: MOVSB and MOVSW has no effect on the Flags

Storing a String

STOSB ; store string byte

STOSB moves the contents of AL register to the byte address ES: DI (destination).

DI is incremented if DF = 0 and decremented if DF = 1

STOSW ; store string word

STOSW moves the contents of AX register to the word address ES: DI (destination).

DI is increased by 2 if DF = 0 and decreased by 2 if DF = 1

STOSB and STOSW has no effect on the Flags

For example the following instruction will store two “A”s in STRING1

MOV AX,@DATA
MOV ES, AX ; Initialize ES
LEA DI, STRING1 ; DI points to source string
CLD ; Process to the right
MOV AL, ’A’ ; Al has character to store
STOSB ; Store an ‘A’
STOSB ; Store another one

Figure 2: STOSB Operation

Lab Exercises:

Task 1

Write an assembly program to copy STRING1 into the STRING2 in reverse order.

Task 2

For the following array,


ARR DW 10, 20, 40, 50, 60,?

Write assembly language code to insert 30 between 20 and 40. (Assume DS and ES have been
initialized to the data segment).

You might also like