SlideShare una empresa de Scribd logo
1 de 31
String Manipulation Instructions
– These are the instructions used for strings for
string movement, Load, Store, Comparison and
Scan.
– A string is a series of bytes or a series of words
in sequential memory locations.
– A ‘B’ in the instruction mnemonic is used to
specifically indicate that a string of bytes is to
be acted upon.
– A ‘W’ in the instruction mnemonic is used to
specifically indicate that a string of words is to
be acted upon.
MOVS/MOVSB/MOVSW
Syntax :-- MOVS destination, source
MOVSB
MOVSW
• The MOVS instruction is used to transfer a byte
or a word from the source string to the destination
string.
•The source must be in the data segment and the
destination in the extra segment.
• The offset of the source byte or a word must be
placed in SI register, which is represented as DS:SI
and the offset of the destination byte or a word
must be placed in DI register, which is represented
as ES:DI
MOVS/MOVSB/MOVSW (contd..)
•On the execution of the instruction, SI and DI are
automatically adjusted by one to the next
element of the source and destination.
•If the Direction Flag is reset (DF = 0), the
registers SI and DI will be incremented by one for
the byte movement and incremented by two for
the word movement.
•If the Direction Flag is set (DF = 1), the registers
SI and DI will be decremented by one for the byte
movement and decremented by two for the word
movement.
MOVS/MOVSB/MOVSW (contd..)
•The DS:SI and ES:DI register must be loaded prior
to the execution of the MOVS instruction.
•MOVSB and MOVSW are the implicit instructions
to move a byte or word string .
•The instruction MOVSB is used to transfer a byte
from the source to destination and the
instruction MOVSW is used to transfer a word
from the source to destination.
•In multiple byte or word moves, the count must
be loaded in CX register which functions as a
counter.
• Operation Performed :--
• ES:[DI]  DS:[SI]
• If a byte movement,
–For DF =0, SI  SI +1 & DI  DI +1
–For DF =1, SI  SI -1 & DI  DI - 1
• If a word movement,
–For DF =0, SI  SI +2 & DI  DI +2
–For DF =1, SI  SI -2 & DI  DI - 2
MOVS/MOVSB/MOVSW (contd..)
MOVS D_STRING, S_STRINGMOVSB ; moves a byteMOVSW ; moves a word
• Examples :--
MOV AX, DATA ; initialize DS and ES
MOV DS,AX
MOV ES,AX
CLD ; Clear DF for incrementing
SI and DI
LEA SI, S_STRING ; initialize SI & DI
LEA DI, D_STRING
MOVS/MOVSB/MOVSW (contd..)
LODS/LODSB/LODSW
Syntax :-- LODS source
LODSB
LODSW
• The LODS instruction is used to transfer a
byte or a word from the source string pointed
by SI in DS to AL for byte or AX for word
•The offset of the source byte or a word must
be placed in SI register, which is represented as
DS:SI
LODS/LODSB/LODSW (contd..)
•On the execution of the instruction, SI is
automatically adjusted by one to the next
element of the source and destination.
•If the Direction Flag is reset (DF = 0), the
registers SI will be incremented by one for the
byte movement and incremented by two for the
word movement.
•If the Direction Flag is set (DF = 1), the registers
SI will be decremented by one for the byte
movement and decremented by two for the word
movement.
LODS/LODSB/LODSW (contd..)
•On the execution of the instruction, SI is
automatically adjusted by one to the next
element of the source and destination.
•If the Direction Flag is reset (DF = 0), the register
SI will be incremented by one for the byte
movement and incremented by two for the word
movement.
•If the Direction Flag is set (DF = 1), the register SI
will be decremented by one for the byte
movement and decremented by two for the word
movement.
• Operation Performed :--
• If a byte movement,
–AL  DS:[SI]
–For DF =0, SI  SI +1
–For DF =1, SI  SI -1
• If a word movement,
–AX  DS:[SI]
–For DF =0, SI  SI +2
–For DF =1, SI  SI -2
LODS/LODSB/LODSW (contd..)
LODSW ; LOADS a word to AXLODS S_STRINGLODSB ; loads a byte to AL
• Examples :--
MOV AX, DATA ; initialize DS and ES
MOV DS,AX
CLD ; DF =0 for Incrementing
SI
LEA SI, S_STRING ; initialize SI
LODS/LODSB/LODSW (contd..)
STOS/STOSB/STOSW
Syntax :-- STOS destination
STOSB
STOSW
• The LODS instruction is used to transfer a
byte or a word from AL for byte or AX for word
to the destination string pointed by DI in ES.
•The offset of the destination byte or a word
must be placed in DI register, which is
represented as ES:DI
STOS/STOSB/STOSW (contd..)
•In the STOS instruction, the destination must be
declared as either DB or DW.
•STOSB and STOSW are the implicit instructions
to load a byte or word string .
•The instruction STOSB is used to store a byte
from the source AL to destination and the
instruction STOSW is used to store a word from
the source AX to destination.
•In multiple byte or word moves, the count must
be loaded in CX register which functions as a
counter.
STOS/STOSB/STOSW (contd..)
•On the execution of the instruction, DI is
automatically adjusted by one to the next
element of the destination.
•If the Direction Flag is reset (DF = 0), the register
DI will be incremented by one for the byte
movement and incremented by two for the word
movement.
•If the Direction Flag is set (DF = 1), the register
DI will be decremented by one for the byte
movement and decremented by two for the word
movement.
• Operation Performed :--
• If a byte movement,
–ES:[DI] AL
–For DF =0, DI  DI +1
–For DF =1, DI  DI -1
• If a word movement,
–ES:[DI]  AX
–For DF =0, DI  DI +2
–For DF =1, DI  DI -2
STOS/STOSB/STOSW (contd..)
STOSB ; Stores byte from AL to
destination
STOS D_STRING ; Stores a byte or word in
AL or AX dep on D_string
to D_string
• Examples :--
MOV AX, DATA ; initialize ES
MOV ES,AX
CLD ; DF =0 for Incrementing
SI
LEA DI, D_STRING ; initialize DI
STOSW ; Stores a word from AX to
destination
STOS/STOSB/STOSW (contd..)
CMPS/CMPSB/CMPSW
Syntax :-- CMPS destination, source
CMPSB
CMPSW
• The CMPS instruction is used to compare a byte
or a word in the source string with a byte or a
word in the destination string.
•The source must be in the data segment and the
destination in the extra segment.
• The offset of the source byte or a word must be
placed in SI register, which is represented as DS:SI
and the offset of the destination byte or a word
must be placed in DI register, which is represented
as ES:DI
CMPS/CMPSB/CMPSW (contd..)
•On the execution of the instruction, SI and DI are
automatically adjusted by one to the next
element of the source and destination.
•If the Direction Flag is reset (DF = 0), the
registers SI and DI will be incremented by one for
the byte comparison and incremented by two for
the word comparison.
•If the Direction Flag is set (DF = 1), the registers
SI and DI will be decremented by one for the byte
comparison and decremented by two for the
word comparison
CMPS/CMPSB/CMPSW (contd..)
•The DS:SI and ES:DI register must be loaded prior
to the execution of the CMPS instruction.
•CMPSB and CMPSW are the implicit instructions
to move a byte or word string .
•The instruction CMPSB is used to compare a
byte from the source with destination and the
instruction CMPSW is used to compare a word in
the source with destination.
•In multiple byte or word comparison, the count
must be loaded in CX register which functions as
a counter.
•All conditional flags are affected
• Operation Performed :--
• If dest string > source string then
CF =0, ZF = 0, SF = 0
• If dest string < source string then
CF =1, ZF = 0, SF = 1
• If dest string = source string then
CF =0, ZF = 1, SF = 0
• If a byte comparison,
– For DF =0, SI  SI +1 & DI  DI +1
– For DF =1, SI  SI -1 & DI  DI - 1
• If a word comparison,
– For DF =0, SI  SI +2 & DI  DI +2
– For DF =1, SI  SI -2 & DI  DI - 2
CMPS/CMPSB/CMPSW (contd..)
CMPSW ; compares a wordCMPS D_STRING, S_STRINGCMPSB ; compares a byte
• Examples :--
MOV AX, DATA ; initialize DS and ES
MOV DS,AX
MOV ES,AX
CLD ; Clear DF for incrementing
SI and DI
LEA SI, S_STRING ; initialize SI & DI
LEA DI, D_STRING
CMPS/CMPSB/CMPSW (contd..)
SCAS/SCASB/SCASW
Syntax :-- SCAS destination
SCASB
SCASW
• The SCAS instruction is used to scan a byte or
a word with a byte in AL or word in AX.
•The offset of the destination byte or a word
must be placed in DI register, which is
represented as ES:DI
SCAS/SCASB/SCASW (contd..)
•On the execution of the instruction, DI is
automatically adjusted by one to the next
element of the destination.
•If the Direction Flag is reset (DF = 0), the register
DI will be incremented by one for the byte scan
and incremented by two for the word scan.
•If the Direction Flag is set (DF = 1), the register
DI will be decremented by one for the byte scan
and decremented by two for the word scan
SCAS/SCASB/SCASW (contd..)
•In the SCAS instruction, the destination must be
declared as either DB or DW.
•SCASB and SCASW are the implicit instructions
to scan a byte or word in a string .
•The instruction SCASB is used to scan a byte and
the instruction SCASW is used to scan a word.
•In multiple byte or word moves, the count must
be loaded in CX register which functions as a
counter.
• Operation Performed :--
• If byte in AL or word in AX > dest string byte or word then
CF =0, ZF = 0, SF = 0
• If byte in AL or word in AX < dest string byte or word then
CF =1, ZF = 0, SF = 1
• If byte in AL or word in AX = dest string byte or word then
CF =0, ZF = 1, SF = 0
• If a byte scan,
– For DF =0, SI  SI +1 & DI  DI +1
– For DF =1, SI  SI -1 & DI  DI - 1
• If a word scan,
– For DF =0, SI  SI +2 & DI  DI +2
– For DF =1, SI  SI -2 & DI  DI - 2
SCAS/SCASB/SCASW (contd..)
• Examples :--
MOV AX, DATA ; initialize ES
MOV ES,AX
CLD ; DF =0 for Incrementing
SI
LEA DI, D_STRING ; initialize DI
MOV AL,’V’
SCAS D_STRING ; Scans a byte or word in
AL or AX dep on D_string
to D_string
SCASB ; Scans byte from AL to
destination
SCASW ; Scans a word from AX to
destination
SCAS/SCASB/SCASW (contd..)
REP (Instruction Prefix)
The REP instruction prefix is used in string
instructions and interpreted as “Repeat while not
end of string”
In REP prefix, CX register is loaded with the count.
Operation performed :--
• While CX <>0, perform the string operation
• CX  CX - 1
REP (Instruction Prefix) contd..
Example :--
MOV AX,DATA
MOV DS, AX
MOV ES,AX
CLD
MOV CX, string _length
LEA SI,S_STRING
LEA DI,D_STRING
REP CMPSB
REPE/REPZ (Instruction Prefix)
The REPE instruction prefix is used in string
instructions and interpreted as “Repeat while not
end of string and string equal” (CX<>0 and ZF =1)
In REPE prefix, CX register is loaded with the
count.
Operation performed :--
• While CX <>0 & ZF -1 ,
perform the string operation
• CX  CX - 1
REPE/REPZ (Instruction Prefix) contd..
Example :--
MOV AX,DATA
MOV DS, AX
MOV ES,AX
CLD
MOV CX, string _length
LEA SI,S_STRING
LEA DI,D_STRING
REPE CMPSB
JE ST_EQUAL
NT_EQUAL: MOV AX, 01
JMP END
ST_EQUAL: MOV AX, 00
REPNE/REPNZ (Instruction Prefix)
The REPNE instruction prefix is used in string
instructions and interpreted as “Repeat while not
end of string and string not equal” (CX<>0 and
ZF =0)
In REPNE prefix, CX register is loaded with the
count.
Operation performed :--
• While CX <>0 & ZF = 0 ,
perform the string operation
• CX  CX - 1

Más contenido relacionado

Similar a Chapter3 8086inst stringsl

15CS44 MP &MC Module 3
15CS44 MP &MC Module 315CS44 MP &MC Module 3
15CS44 MP &MC Module 3RLJIT
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptxNishatNishu5
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorAshita Agrawal
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4Motaz Saad
 
Notes arithmetic instructions
Notes arithmetic instructionsNotes arithmetic instructions
Notes arithmetic instructionsHarshitParkar6677
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086Akhila Rahul
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086Mahalakshmiv11
 
10 8086 instruction set
10 8086 instruction set10 8086 instruction set
10 8086 instruction setShivam Singhal
 
Instruction set-of-8086
Instruction set-of-8086Instruction set-of-8086
Instruction set-of-8086mudulin
 
Instructionsetof8086 by Alwani
Instructionsetof8086 by AlwaniInstructionsetof8086 by Alwani
Instructionsetof8086 by AlwaniHimanshu Alwani
 
N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)Selomon birhane
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.pptinian2
 
ppt-U2 - (Instruction Set of 8086, Simple programs).pptx
ppt-U2 - (Instruction Set of 8086, Simple programs).pptxppt-U2 - (Instruction Set of 8086, Simple programs).pptx
ppt-U2 - (Instruction Set of 8086, Simple programs).pptxRaviKiranVarma4
 
Instruction 7.pptx
Instruction 7.pptxInstruction 7.pptx
Instruction 7.pptxHebaEng
 
microcomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instructionmicrocomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instructionramya marichamy
 

Similar a Chapter3 8086inst stringsl (20)

15CS44 MP &MC Module 3
15CS44 MP &MC Module 315CS44 MP &MC Module 3
15CS44 MP &MC Module 3
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptx
 
Instruction set
Instruction setInstruction set
Instruction set
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 Microprocessor
 
Assembly language
Assembly languageAssembly language
Assembly language
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
 
Notes arithmetic instructions
Notes arithmetic instructionsNotes arithmetic instructions
Notes arithmetic instructions
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086
 
10 8086 instruction set
10 8086 instruction set10 8086 instruction set
10 8086 instruction set
 
Instruction set-of-8086
Instruction set-of-8086Instruction set-of-8086
Instruction set-of-8086
 
Instructionsetof8086 by Alwani
Instructionsetof8086 by AlwaniInstructionsetof8086 by Alwani
Instructionsetof8086 by Alwani
 
Microprocessor
MicroprocessorMicroprocessor
Microprocessor
 
N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)
 
8086 add mod
8086 add mod8086 add mod
8086 add mod
 
Al2ed chapter10
Al2ed chapter10Al2ed chapter10
Al2ed chapter10
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.ppt
 
ppt-U2 - (Instruction Set of 8086, Simple programs).pptx
ppt-U2 - (Instruction Set of 8086, Simple programs).pptxppt-U2 - (Instruction Set of 8086, Simple programs).pptx
ppt-U2 - (Instruction Set of 8086, Simple programs).pptx
 
Instruction 7.pptx
Instruction 7.pptxInstruction 7.pptx
Instruction 7.pptx
 
microcomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instructionmicrocomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instruction
 

Más de HarshitParkar6677 (20)

Wi fi hacking
Wi fi hackingWi fi hacking
Wi fi hacking
 
D dos attack
D dos attackD dos attack
D dos attack
 
Notes chapter 6
Notes chapter  6Notes chapter  6
Notes chapter 6
 
Interface notes
Interface notesInterface notes
Interface notes
 
Chapter6 2
Chapter6 2Chapter6 2
Chapter6 2
 
Chapter6
Chapter6Chapter6
Chapter6
 
8086 cpu 1
8086 cpu 18086 cpu 1
8086 cpu 1
 
Chapter 6 notes
Chapter 6 notesChapter 6 notes
Chapter 6 notes
 
Chapter 5 notes
Chapter 5 notesChapter 5 notes
Chapter 5 notes
 
Chap6 procedures &amp; macros
Chap6 procedures &amp; macrosChap6 procedures &amp; macros
Chap6 procedures &amp; macros
 
Chapter 5 notes new
Chapter 5 notes newChapter 5 notes new
Chapter 5 notes new
 
Notes all instructions
Notes all instructionsNotes all instructions
Notes all instructions
 
Notes aaa aa
Notes aaa aaNotes aaa aa
Notes aaa aa
 
Notes 8086 instruction format
Notes 8086 instruction formatNotes 8086 instruction format
Notes 8086 instruction format
 
Misc
MiscMisc
Misc
 
Copy of 8086inst logical
Copy of 8086inst logicalCopy of 8086inst logical
Copy of 8086inst logical
 
Copy of 8086inst logical
Copy of 8086inst logicalCopy of 8086inst logical
Copy of 8086inst logical
 
Chapter3 program flow control instructions
Chapter3 program flow control instructionsChapter3 program flow control instructions
Chapter3 program flow control instructions
 
Chapter3 8086inst logical 2
Chapter3 8086inst logical 2Chapter3 8086inst logical 2
Chapter3 8086inst logical 2
 
Chapter 3 8086 ins2 math
Chapter 3 8086 ins2 mathChapter 3 8086 ins2 math
Chapter 3 8086 ins2 math
 

Último

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxNadaHaitham1
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 

Último (20)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 

Chapter3 8086inst stringsl

  • 1. String Manipulation Instructions – These are the instructions used for strings for string movement, Load, Store, Comparison and Scan. – A string is a series of bytes or a series of words in sequential memory locations. – A ‘B’ in the instruction mnemonic is used to specifically indicate that a string of bytes is to be acted upon. – A ‘W’ in the instruction mnemonic is used to specifically indicate that a string of words is to be acted upon.
  • 2. MOVS/MOVSB/MOVSW Syntax :-- MOVS destination, source MOVSB MOVSW • The MOVS instruction is used to transfer a byte or a word from the source string to the destination string. •The source must be in the data segment and the destination in the extra segment. • The offset of the source byte or a word must be placed in SI register, which is represented as DS:SI and the offset of the destination byte or a word must be placed in DI register, which is represented as ES:DI
  • 3. MOVS/MOVSB/MOVSW (contd..) •On the execution of the instruction, SI and DI are automatically adjusted by one to the next element of the source and destination. •If the Direction Flag is reset (DF = 0), the registers SI and DI will be incremented by one for the byte movement and incremented by two for the word movement. •If the Direction Flag is set (DF = 1), the registers SI and DI will be decremented by one for the byte movement and decremented by two for the word movement.
  • 4. MOVS/MOVSB/MOVSW (contd..) •The DS:SI and ES:DI register must be loaded prior to the execution of the MOVS instruction. •MOVSB and MOVSW are the implicit instructions to move a byte or word string . •The instruction MOVSB is used to transfer a byte from the source to destination and the instruction MOVSW is used to transfer a word from the source to destination. •In multiple byte or word moves, the count must be loaded in CX register which functions as a counter.
  • 5. • Operation Performed :-- • ES:[DI]  DS:[SI] • If a byte movement, –For DF =0, SI  SI +1 & DI  DI +1 –For DF =1, SI  SI -1 & DI  DI - 1 • If a word movement, –For DF =0, SI  SI +2 & DI  DI +2 –For DF =1, SI  SI -2 & DI  DI - 2 MOVS/MOVSB/MOVSW (contd..)
  • 6. MOVS D_STRING, S_STRINGMOVSB ; moves a byteMOVSW ; moves a word • Examples :-- MOV AX, DATA ; initialize DS and ES MOV DS,AX MOV ES,AX CLD ; Clear DF for incrementing SI and DI LEA SI, S_STRING ; initialize SI & DI LEA DI, D_STRING MOVS/MOVSB/MOVSW (contd..)
  • 7. LODS/LODSB/LODSW Syntax :-- LODS source LODSB LODSW • The LODS instruction is used to transfer a byte or a word from the source string pointed by SI in DS to AL for byte or AX for word •The offset of the source byte or a word must be placed in SI register, which is represented as DS:SI
  • 8. LODS/LODSB/LODSW (contd..) •On the execution of the instruction, SI is automatically adjusted by one to the next element of the source and destination. •If the Direction Flag is reset (DF = 0), the registers SI will be incremented by one for the byte movement and incremented by two for the word movement. •If the Direction Flag is set (DF = 1), the registers SI will be decremented by one for the byte movement and decremented by two for the word movement.
  • 9. LODS/LODSB/LODSW (contd..) •On the execution of the instruction, SI is automatically adjusted by one to the next element of the source and destination. •If the Direction Flag is reset (DF = 0), the register SI will be incremented by one for the byte movement and incremented by two for the word movement. •If the Direction Flag is set (DF = 1), the register SI will be decremented by one for the byte movement and decremented by two for the word movement.
  • 10. • Operation Performed :-- • If a byte movement, –AL  DS:[SI] –For DF =0, SI  SI +1 –For DF =1, SI  SI -1 • If a word movement, –AX  DS:[SI] –For DF =0, SI  SI +2 –For DF =1, SI  SI -2 LODS/LODSB/LODSW (contd..)
  • 11. LODSW ; LOADS a word to AXLODS S_STRINGLODSB ; loads a byte to AL • Examples :-- MOV AX, DATA ; initialize DS and ES MOV DS,AX CLD ; DF =0 for Incrementing SI LEA SI, S_STRING ; initialize SI LODS/LODSB/LODSW (contd..)
  • 12. STOS/STOSB/STOSW Syntax :-- STOS destination STOSB STOSW • The LODS instruction is used to transfer a byte or a word from AL for byte or AX for word to the destination string pointed by DI in ES. •The offset of the destination byte or a word must be placed in DI register, which is represented as ES:DI
  • 13. STOS/STOSB/STOSW (contd..) •In the STOS instruction, the destination must be declared as either DB or DW. •STOSB and STOSW are the implicit instructions to load a byte or word string . •The instruction STOSB is used to store a byte from the source AL to destination and the instruction STOSW is used to store a word from the source AX to destination. •In multiple byte or word moves, the count must be loaded in CX register which functions as a counter.
  • 14. STOS/STOSB/STOSW (contd..) •On the execution of the instruction, DI is automatically adjusted by one to the next element of the destination. •If the Direction Flag is reset (DF = 0), the register DI will be incremented by one for the byte movement and incremented by two for the word movement. •If the Direction Flag is set (DF = 1), the register DI will be decremented by one for the byte movement and decremented by two for the word movement.
  • 15. • Operation Performed :-- • If a byte movement, –ES:[DI] AL –For DF =0, DI  DI +1 –For DF =1, DI  DI -1 • If a word movement, –ES:[DI]  AX –For DF =0, DI  DI +2 –For DF =1, DI  DI -2 STOS/STOSB/STOSW (contd..)
  • 16. STOSB ; Stores byte from AL to destination STOS D_STRING ; Stores a byte or word in AL or AX dep on D_string to D_string • Examples :-- MOV AX, DATA ; initialize ES MOV ES,AX CLD ; DF =0 for Incrementing SI LEA DI, D_STRING ; initialize DI STOSW ; Stores a word from AX to destination STOS/STOSB/STOSW (contd..)
  • 17. CMPS/CMPSB/CMPSW Syntax :-- CMPS destination, source CMPSB CMPSW • The CMPS instruction is used to compare a byte or a word in the source string with a byte or a word in the destination string. •The source must be in the data segment and the destination in the extra segment. • The offset of the source byte or a word must be placed in SI register, which is represented as DS:SI and the offset of the destination byte or a word must be placed in DI register, which is represented as ES:DI
  • 18. CMPS/CMPSB/CMPSW (contd..) •On the execution of the instruction, SI and DI are automatically adjusted by one to the next element of the source and destination. •If the Direction Flag is reset (DF = 0), the registers SI and DI will be incremented by one for the byte comparison and incremented by two for the word comparison. •If the Direction Flag is set (DF = 1), the registers SI and DI will be decremented by one for the byte comparison and decremented by two for the word comparison
  • 19. CMPS/CMPSB/CMPSW (contd..) •The DS:SI and ES:DI register must be loaded prior to the execution of the CMPS instruction. •CMPSB and CMPSW are the implicit instructions to move a byte or word string . •The instruction CMPSB is used to compare a byte from the source with destination and the instruction CMPSW is used to compare a word in the source with destination. •In multiple byte or word comparison, the count must be loaded in CX register which functions as a counter. •All conditional flags are affected
  • 20. • Operation Performed :-- • If dest string > source string then CF =0, ZF = 0, SF = 0 • If dest string < source string then CF =1, ZF = 0, SF = 1 • If dest string = source string then CF =0, ZF = 1, SF = 0 • If a byte comparison, – For DF =0, SI  SI +1 & DI  DI +1 – For DF =1, SI  SI -1 & DI  DI - 1 • If a word comparison, – For DF =0, SI  SI +2 & DI  DI +2 – For DF =1, SI  SI -2 & DI  DI - 2 CMPS/CMPSB/CMPSW (contd..)
  • 21. CMPSW ; compares a wordCMPS D_STRING, S_STRINGCMPSB ; compares a byte • Examples :-- MOV AX, DATA ; initialize DS and ES MOV DS,AX MOV ES,AX CLD ; Clear DF for incrementing SI and DI LEA SI, S_STRING ; initialize SI & DI LEA DI, D_STRING CMPS/CMPSB/CMPSW (contd..)
  • 22. SCAS/SCASB/SCASW Syntax :-- SCAS destination SCASB SCASW • The SCAS instruction is used to scan a byte or a word with a byte in AL or word in AX. •The offset of the destination byte or a word must be placed in DI register, which is represented as ES:DI
  • 23. SCAS/SCASB/SCASW (contd..) •On the execution of the instruction, DI is automatically adjusted by one to the next element of the destination. •If the Direction Flag is reset (DF = 0), the register DI will be incremented by one for the byte scan and incremented by two for the word scan. •If the Direction Flag is set (DF = 1), the register DI will be decremented by one for the byte scan and decremented by two for the word scan
  • 24. SCAS/SCASB/SCASW (contd..) •In the SCAS instruction, the destination must be declared as either DB or DW. •SCASB and SCASW are the implicit instructions to scan a byte or word in a string . •The instruction SCASB is used to scan a byte and the instruction SCASW is used to scan a word. •In multiple byte or word moves, the count must be loaded in CX register which functions as a counter.
  • 25. • Operation Performed :-- • If byte in AL or word in AX > dest string byte or word then CF =0, ZF = 0, SF = 0 • If byte in AL or word in AX < dest string byte or word then CF =1, ZF = 0, SF = 1 • If byte in AL or word in AX = dest string byte or word then CF =0, ZF = 1, SF = 0 • If a byte scan, – For DF =0, SI  SI +1 & DI  DI +1 – For DF =1, SI  SI -1 & DI  DI - 1 • If a word scan, – For DF =0, SI  SI +2 & DI  DI +2 – For DF =1, SI  SI -2 & DI  DI - 2 SCAS/SCASB/SCASW (contd..)
  • 26. • Examples :-- MOV AX, DATA ; initialize ES MOV ES,AX CLD ; DF =0 for Incrementing SI LEA DI, D_STRING ; initialize DI MOV AL,’V’ SCAS D_STRING ; Scans a byte or word in AL or AX dep on D_string to D_string SCASB ; Scans byte from AL to destination SCASW ; Scans a word from AX to destination SCAS/SCASB/SCASW (contd..)
  • 27. REP (Instruction Prefix) The REP instruction prefix is used in string instructions and interpreted as “Repeat while not end of string” In REP prefix, CX register is loaded with the count. Operation performed :-- • While CX <>0, perform the string operation • CX  CX - 1
  • 28. REP (Instruction Prefix) contd.. Example :-- MOV AX,DATA MOV DS, AX MOV ES,AX CLD MOV CX, string _length LEA SI,S_STRING LEA DI,D_STRING REP CMPSB
  • 29. REPE/REPZ (Instruction Prefix) The REPE instruction prefix is used in string instructions and interpreted as “Repeat while not end of string and string equal” (CX<>0 and ZF =1) In REPE prefix, CX register is loaded with the count. Operation performed :-- • While CX <>0 & ZF -1 , perform the string operation • CX  CX - 1
  • 30. REPE/REPZ (Instruction Prefix) contd.. Example :-- MOV AX,DATA MOV DS, AX MOV ES,AX CLD MOV CX, string _length LEA SI,S_STRING LEA DI,D_STRING REPE CMPSB JE ST_EQUAL NT_EQUAL: MOV AX, 01 JMP END ST_EQUAL: MOV AX, 00
  • 31. REPNE/REPNZ (Instruction Prefix) The REPNE instruction prefix is used in string instructions and interpreted as “Repeat while not end of string and string not equal” (CX<>0 and ZF =0) In REPNE prefix, CX register is loaded with the count. Operation performed :-- • While CX <>0 & ZF = 0 , perform the string operation • CX  CX - 1