0% found this document useful (0 votes)
3 views3 pages

String Insruction

Uploaded by

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

String Insruction

Uploaded by

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

ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY

1.7 STRING MANIPULATION INSTRUCTIONS

A series of data byte or word available in memory at consecutive locations, to be


referred as Byte String or Word String. A String of characters may be located in
consecutive memory locations, where each character may be represented by its ASCII
equivalent. The 8086 supports a set of more powerful instructions for string
manipulations for referring to a string, two parameters are required.

I. Starting and End Address of the String.


II. Length of the String.

The length of the string is usually stored as count in the CX register. The
incrementing or decrementing of the pointer, in string instructions, depends upon the
Direction Flag (DF) Status. If it is a Byte string operation, the index registers are updated
by one. On the other hand, if it is a word string operation, the index registers are updated
by two.

REP: Repeat Instruction Prefix

This instruction is used as a prefix to other instructions, the instruction to which


the REP prefix is provided, is executed repeatedly until the CX register becomes zero (at
each iteration CX is automatically decremented by one). i. REPE / REPZ - repeat
operation while equal / zero. ii. REPNE / REPNZ - repeat operation while not equal / not
zero. These are used for CMPS, SCAS instructions only, as instruction prefixes.

MOVSB / MOVSW: Move String Byte or String Word

Suppose a string of bytes stored in a set of consecutive memory locations is to be


moved to another set of destination locations. The starting byte of source string is located
in the memory location whose address may be computed using SI (Source Index) and DS
(Data Segment) contents. The starting address of the destination locations where this
string has to be relocated is given by DI (Destination Index) and ES (Extra Segment)
contents.

EC8691 MICROPROCESSORS AND MICROCONTROLLERS


ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY

Example: Block Transfer program using the move string instruction


MOV AX, DATA SEG ADDR
MOV DS, AX
MOV ES, AX
MOV SI, BLK 1 ADDR
MOV DI, BLK 2 ADDR
MOV CX, Count
CDF
REP MOVSB
HLT

CMPS: Compare String Byte or String Word

The CMPS instruction can be used to compare two strings of byte or words. The
length of the string must be stored in the register CX. If both the byte or word strings are
equal, zero Flag is set. The REP instruction Prefix is used to repeat the operation till CX
(counter) becomes zero or the condition specified by the REP Prefix is False.

SCAN: Scan String Byte or String Word

This instruction scans a string of bytes or words for an operand byte or word
specified in the register AL or AX. The String is pointed to by ES: DI register pair. The
length of the string stored in CX. The DF controls the mode for scanning of the string.
Whenever a match to the specified operand is found in the string, execution stops and the
zero Flag is set. If no match is found, the zero flag is reset.

LODS: Load String Byte or String Word

The LODS instruction loads the AL / AX register by the content of a string pointed
to by DS: SI register pair. The SI is modified automatically depending upon DF, If it is a

EC8691 MICROPROCESSORS AND MICROCONTROLLERS


ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY

byte transfer (LODSB), the SI is modified by one and if it is a word transfer (LODSW),
the SI is modified by two. No other Flags are affected by this instruction.

STOS: Store String Byte or String Word

The STOS instruction Stores the AL / AX register contents to a location in the


string pointer by ES: DI register pair. The DI is modified accordingly, No Flags are
affected by this instruction. The direction Flag controls the String instruction execution,
The source index SI and Destination Index DI are modified after each iteration
automatically. If DF=1, then the execution follows auto decrement mode, SI and DI are
decremented automatically after each iteration. If DF=0, then the execution follows auto
increment mode. In this mode, SI and DI are incremented automatically after each
iteration.

AUTO INDEXING FOR STRING INSTRUCTIONS:


SI & DI addresses are either automatically incremented or decremented
based on the setting of the direction flag DF. When CLD (Clear Direction
Flag) is executed DF=0 permits auto increment by 1. When STD (Set
Direction Flag) is executed DF=1 permits auto decrement by 1.

EC8691 MICROPROCESSORS AND MICROCONTROLLERS

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy