0% found this document useful (0 votes)
16 views4 pages

String Instructions

The document outlines string instructions in assembly language, which are used to manipulate strings of data. Key instructions include MOVS for moving strings, CMPS for comparing strings, SCAS for scanning strings, LODS for loading strings, STOS for storing strings, and REP for repeating string operations. Each instruction affects specific flags that determine the behavior of the operations performed.

Uploaded by

Sarah Sheikh
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)
16 views4 pages

String Instructions

The document outlines string instructions in assembly language, which are used to manipulate strings of data. Key instructions include MOVS for moving strings, CMPS for comparing strings, SCAS for scanning strings, LODS for loading strings, STOS for storing strings, and REP for repeating string operations. Each instruction affects specific flags that determine the behavior of the operations performed.

Uploaded by

Sarah Sheikh
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/ 4

7.

String Instructions
String instructions in assembly are used to manipulate strings of data, often in the form of
arrays or sequences of bytes. These instructions help you efficiently perform operations on
sequences of characters or words.

A) MOVS (Move String)


The MOVS instruction is used to move a string of bytes or words from the source to the
destination. The source is typically pointed to by the SI (Source Index) register, and the
destination is pointed to by the DI (Destination Index) register.

Syntax:
assembly
CopyEdit
MOVS

Example Explanation

MOVS Move the byte or word from the address pointed by SI to the address pointed by DI.

MOVSB Move byte from DS:SI to ES:DI.

MOVSW Move word from DS:SI to ES:DI.

✔ Flags Affected:

●​ DF (Direction Flag): Determines the direction of the move.


○​ If DF = 0, the string is moved from low to high memory (incrementing SI and
DI).
○​ If DF = 1, the string is moved from high to low memory (decrementing SI and
DI).

B) CMPS (Compare String)


The CMPS instruction compares two strings byte by byte or word by word. The comparison
is performed between the byte or word pointed to by SI and DI.

Syntax:
assembly
CopyEdit
CMPS

Example Explanation

CMPS Compare the byte or word at DS:SI with the byte or word at ES:DI.

✔ Flags Affected:

●​ ZF (Zero Flag): Set if the strings are equal.


●​ SF (Sign Flag): Set if the string at DS:SI is greater than the string at ES:DI.
●​ CF (Carry Flag): Set if a borrow occurs in the comparison (unsigned comparison).

C) SCAS (Scan String)


The SCAS instruction compares a byte or word in the AL/AX register with a byte or word at
the address pointed to by DI. It is often used to search for a particular value in a string.

Syntax:
assembly
CopyEdit
SCAS

Example Explanation

SCAS Compare AL with the byte at ES:DI (for bytes) or compare AX with the word
at ES:DI (for words).

✔ Flags Affected:

●​ ZF (Zero Flag): Set if the value in AL or AX matches the byte or word at ES:DI.
●​ SF (Sign Flag): Set based on the result of the comparison.
●​ CF (Carry Flag): Set if a borrow occurred (unsigned comparison).

D) LODS (Load String)


The LODS instruction loads a byte or word from the string into the AL or AX register. The
data is taken from the address pointed to by SI.

Syntax:
assembly
CopyEdit
LODS

Example Explanation

LODS Load a byte (from SI to AL) or word (from SI to AX) into the appropriate
register.

✔ Flags Affected:

●​ SI: Increments or decrements depending on the DF flag.


●​ AL or AX: Contains the loaded value.

E) STOS (Store String)


The STOS instruction stores the byte or word in AL or AX into the string at the address
pointed to by DI.

Syntax:
assembly
CopyEdit
STOS

Example Explanation

STOS Store the value in AL or AX at the address pointed to by DI.

✔ Flags Affected:

●​ DI: Increments or decrements depending on the DF flag.

F) REP (Repeat Prefix)


The REP prefix is used in combination with string instructions to repeat them a specified
number of times. It is useful for repeating string operations.

Syntax:
assembly
CopyEdit
REP instruction
Example Explanation

REP Repeats the MOVSB instruction for the number of times specified by CX
MOVSB (default is 1).

REPNE Repeats CMPSB while ZF = 0 (i.e., while strings are not equal).
CMPSB

✔ CX Register:

●​ The CX register contains the number of repetitions.


●​ The REPNE (repeat while not equal) and REPE (repeat while equal) prefixes are
variations that depend on the status of ZF.

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