SlideShare a Scribd company logo
String Instructions
in Assembly
Language
String instructions in assembly language offer a powerful way to
manipulate and process sequences of characters, which are
essential for tasks like text processing, data manipulation, and
user input handling.
by Susmitha .G
String Fundamentals
SI (Data Segment)
The source index (SI) register
points to the beginning of the
string within the data segment,
where the string is stored.
DI (Extra Segment)
The destination index (DI) register
points to the location in the extra
segment where the string will be
copied or processed.
Direction Flag (DF)
The direction flag (DF) determines
the direction of string processing.
DF=0 indicates increment, while
DF=1 indicates decrement.
Types of String Instructions
1 Repeat Instruction
These instructions are used to repeat a specific string
operation until a condition is met, controlled by the CX
register.
2 Move Instructions (MOVS)
These instructions move data from one memory
location to another, often used for copying strings.
3 Compare Instructions (CMPS)
These instructions compare the contents of two
memory locations, setting flags based on the
comparison result, used for finding patterns within
strings.
4 Scan Instructions (SCAS)
These instructions scan a string for a specific value
stored in the AL or AX register, used for finding a
specific character or pattern.
5 Load Instructions (LODS)
These instructions load a byte or word from a string
location pointed to by SI into AL or AX, used for
accessing individual characters.
6 Store Instructions (STOS)
These instructions store a byte or word from AL or AX
into a string location pointed to by DI, used for writing
to a string.
Move from Memory to Memory (MOVS)
MOVS
The MOVS instruction
copies the contents of a
byte or word from the
source address DS:SI to
the destination address
ES:DI.
MOVSB
This variant copies a
single byte from the
source address DS:SI to
the destination address
ES:DI.
MOVSW
This variant copies a
single word from the
source address DS:SI to
the destination address
ES:DI.
MOVSD
This variant copies a
double word from the
source address DS:SI to
the destination address
ES:DI.
Example: MOVS Instruction
Opcode Instruction Description
A4 MOVS m8, m8 Move byte at address DS:
(E)SI to address ES:(E)DI
A5 MOVS m16, m16 Move word at address DS:
(E)SI to address ES:(E)DI
A5 MOVS m32, m32 Move doubleword at
address DS:(E)SI to address
ES:(E)DI
A4 MOVSB Move byte at address DS:
(E)SI to address ES:(E)DI
A5 MOVSW Move word at address DS:
(E)SI to address ES:(E)DI
A5 MOVSD Move doubleword at
address DS:(E)SI to address
ES:(E)DI
Compare Memory with
Memory (CMPS)
Compare Logic
The CMPS instruction compares the values pointed to by DS:SI
and ES:DI, setting flags based on the comparison result. The
operands themselves are not altered.
Increment or Decrement
After the comparison, SI and DI are incremented (if DF = 0) or
decremented (if DF = 1), in preparation for comparing the next
element.
Direction Flag
The DF determines the direction of comparison, with DF = 0 for
increment and DF = 1 for decrement.
Scan a String (SCAS)
Scan Purpose
The SCAS instruction scans a string for a specific value stored in the AL or AX
register, comparing each character with the value.
String Location
The string to be scanned is pointed to by the ES:DI register pair.
Length
The CX register holds the length of the string to be scanned.
Direction Flag
The DF controls the direction of scanning. DF=0 increments DI, while DF=1
decrements DI.
Scan a String Example
The SCAS instruction is often used in loops to search for specific patterns or characters within a string. It
compares each character in the string with the value in AL or AX, and sets flags based on the result.
Loading Instructions (LODS)
LODS
The LODS instruction copies a byte or word from a string location pointed to by
SI into AL or AX.
LODSB
This variant loads a byte from the string location pointed to by SI into AL.
LODSW
This variant loads a word from the string location pointed to by SI into AX.
LODS Instructions:
Applications
The LODS instructions are crucial for processing strings character
by character, enabling tasks such as iterating through a string,
extracting specific characters, or performing character-based
operations.

More Related Content

PDF
N_Asm Assembly strings (sol)
PDF
String_manipulations.pdf
PPTX
Arrays, Strings & Loops in assembly Language.pptx
PPT
Al2ed chapter10
PPTX
Byte and string manipulation 8086
PPTX
8086inst stringsl
PPTX
FLAG & PROCESSOR & STRING INSTRUCTIONS.pptx
PPTX
Chap 8086 string
N_Asm Assembly strings (sol)
String_manipulations.pdf
Arrays, Strings & Loops in assembly Language.pptx
Al2ed chapter10
Byte and string manipulation 8086
8086inst stringsl
FLAG & PROCESSOR & STRING INSTRUCTIONS.pptx
Chap 8086 string

Similar to String-Instructions-in-Assembly-Language.pptx (20)

PPTX
Chapter3 8086inst stringsl
PPTX
Instruction Set of 8086 Microprocessor
PPT
Chapter4.3 4-mikroprocessor
PDF
8086 String Instructions.pdf
PPT
Assembly Language String Chapter
PPT
Instruction set
PPT
Al2ed chapter4
PPTX
instructionsetsofjdtufgmictfgfjh8086.pptx
PPTX
[ASM]Lab8
PPTX
microprocesser Chapter three and foure.pptx
PDF
String instruction in assembly language 8086
PPTX
Chapter 4 programming concepts III
PPT
Assembly Language Lecture 4
DOCX
Assembly language
PPTX
Microprocessors-based systems (under graduate course) Lecture 8 of 9
DOCX
Notes 8086 instruction format
PPTX
Module 3 Computer Organization Data Hazards.pptx
PPT
INTRUCTION SET OF 8086 FOR MICROPROCESSOR
PPT
Chap 3_2.ppt
PPT
An instruction is a binary pattern designed inside a microprocessor to perfor...
Chapter3 8086inst stringsl
Instruction Set of 8086 Microprocessor
Chapter4.3 4-mikroprocessor
8086 String Instructions.pdf
Assembly Language String Chapter
Instruction set
Al2ed chapter4
instructionsetsofjdtufgmictfgfjh8086.pptx
[ASM]Lab8
microprocesser Chapter three and foure.pptx
String instruction in assembly language 8086
Chapter 4 programming concepts III
Assembly Language Lecture 4
Assembly language
Microprocessors-based systems (under graduate course) Lecture 8 of 9
Notes 8086 instruction format
Module 3 Computer Organization Data Hazards.pptx
INTRUCTION SET OF 8086 FOR MICROPROCESSOR
Chap 3_2.ppt
An instruction is a binary pattern designed inside a microprocessor to perfor...
Ad

More from susmithaganapathi (6)

PPTX
DNA damage 1.pptx for pg students in studies
PPTX
cell communication and Signalling.pptx for studies
PPTX
Cell cycle control (1).pptx for post graduate studies in final year
PPTX
fruit.pptx for post graduate students studies
PPTX
Biogeochemical cycle.pptx for botanist in studies purpose
PPTX
GMo crops.ppt for botany students seminars
DNA damage 1.pptx for pg students in studies
cell communication and Signalling.pptx for studies
Cell cycle control (1).pptx for post graduate studies in final year
fruit.pptx for post graduate students studies
Biogeochemical cycle.pptx for botanist in studies purpose
GMo crops.ppt for botany students seminars
Ad

Recently uploaded (20)

PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
International_Financial_Reporting_Standa.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Empowerment Technology for Senior High School Guide
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Trump Administration's workforce development strategy
PDF
HVAC Specification 2024 according to central public works department
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PPTX
20th Century Theater, Methods, History.pptx
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
B.Sc. DS Unit 2 Software Engineering.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Environmental Education MCQ BD2EE - Share Source.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
International_Financial_Reporting_Standa.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
Unit 4 Computer Architecture Multicore Processor.pptx
My India Quiz Book_20210205121199924.pdf
Empowerment Technology for Senior High School Guide
LDMMIA Reiki Yoga Finals Review Spring Summer
Trump Administration's workforce development strategy
HVAC Specification 2024 according to central public works department
FORM 1 BIOLOGY MIND MAPS and their schemes
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
20th Century Theater, Methods, History.pptx
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx

String-Instructions-in-Assembly-Language.pptx

  • 1. String Instructions in Assembly Language String instructions in assembly language offer a powerful way to manipulate and process sequences of characters, which are essential for tasks like text processing, data manipulation, and user input handling. by Susmitha .G
  • 2. String Fundamentals SI (Data Segment) The source index (SI) register points to the beginning of the string within the data segment, where the string is stored. DI (Extra Segment) The destination index (DI) register points to the location in the extra segment where the string will be copied or processed. Direction Flag (DF) The direction flag (DF) determines the direction of string processing. DF=0 indicates increment, while DF=1 indicates decrement.
  • 3. Types of String Instructions 1 Repeat Instruction These instructions are used to repeat a specific string operation until a condition is met, controlled by the CX register. 2 Move Instructions (MOVS) These instructions move data from one memory location to another, often used for copying strings. 3 Compare Instructions (CMPS) These instructions compare the contents of two memory locations, setting flags based on the comparison result, used for finding patterns within strings. 4 Scan Instructions (SCAS) These instructions scan a string for a specific value stored in the AL or AX register, used for finding a specific character or pattern. 5 Load Instructions (LODS) These instructions load a byte or word from a string location pointed to by SI into AL or AX, used for accessing individual characters. 6 Store Instructions (STOS) These instructions store a byte or word from AL or AX into a string location pointed to by DI, used for writing to a string.
  • 4. Move from Memory to Memory (MOVS) MOVS The MOVS instruction copies the contents of a byte or word from the source address DS:SI to the destination address ES:DI. MOVSB This variant copies a single byte from the source address DS:SI to the destination address ES:DI. MOVSW This variant copies a single word from the source address DS:SI to the destination address ES:DI. MOVSD This variant copies a double word from the source address DS:SI to the destination address ES:DI.
  • 5. Example: MOVS Instruction Opcode Instruction Description A4 MOVS m8, m8 Move byte at address DS: (E)SI to address ES:(E)DI A5 MOVS m16, m16 Move word at address DS: (E)SI to address ES:(E)DI A5 MOVS m32, m32 Move doubleword at address DS:(E)SI to address ES:(E)DI A4 MOVSB Move byte at address DS: (E)SI to address ES:(E)DI A5 MOVSW Move word at address DS: (E)SI to address ES:(E)DI A5 MOVSD Move doubleword at address DS:(E)SI to address ES:(E)DI
  • 6. Compare Memory with Memory (CMPS) Compare Logic The CMPS instruction compares the values pointed to by DS:SI and ES:DI, setting flags based on the comparison result. The operands themselves are not altered. Increment or Decrement After the comparison, SI and DI are incremented (if DF = 0) or decremented (if DF = 1), in preparation for comparing the next element. Direction Flag The DF determines the direction of comparison, with DF = 0 for increment and DF = 1 for decrement.
  • 7. Scan a String (SCAS) Scan Purpose The SCAS instruction scans a string for a specific value stored in the AL or AX register, comparing each character with the value. String Location The string to be scanned is pointed to by the ES:DI register pair. Length The CX register holds the length of the string to be scanned. Direction Flag The DF controls the direction of scanning. DF=0 increments DI, while DF=1 decrements DI.
  • 8. Scan a String Example The SCAS instruction is often used in loops to search for specific patterns or characters within a string. It compares each character in the string with the value in AL or AX, and sets flags based on the result.
  • 9. Loading Instructions (LODS) LODS The LODS instruction copies a byte or word from a string location pointed to by SI into AL or AX. LODSB This variant loads a byte from the string location pointed to by SI into AL. LODSW This variant loads a word from the string location pointed to by SI into AX.
  • 10. LODS Instructions: Applications The LODS instructions are crucial for processing strings character by character, enabling tasks such as iterating through a string, extracting specific characters, or performing character-based operations.