SlideShare a Scribd company logo
1 of 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

More Related Content

Similar to 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
Instruction setInstruction set
Instruction setKamini Benare
Ā 
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
Ā 
8086 add mod
8086 add mod8086 add mod
8086 add modMohansonale1
Ā 
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 to 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
Ā 

More from HarshitParkar6677

More from 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
Ā 

Recently uploaded

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
Ā 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
Ā 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
Ā 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
Ā 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
Ā 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
Ā 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
Ā 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
Ā 
Model Call Girl in Narela Delhi reach out to us at šŸ”8264348440šŸ”
Model Call Girl in Narela Delhi reach out to us at šŸ”8264348440šŸ”Model Call Girl in Narela Delhi reach out to us at šŸ”8264348440šŸ”
Model Call Girl in Narela Delhi reach out to us at šŸ”8264348440šŸ”soniya singh
Ā 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
Ā 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
Ā 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
Ā 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
Ā 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
Ā 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
Ā 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
Ā 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
Ā 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
Ā 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
Ā 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
Ā 

Recently uploaded (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Ā 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
Ā 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
Ā 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
Ā 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
Ā 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
Ā 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
Ā 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
Ā 
Model Call Girl in Narela Delhi reach out to us at šŸ”8264348440šŸ”
Model Call Girl in Narela Delhi reach out to us at šŸ”8264348440šŸ”Model Call Girl in Narela Delhi reach out to us at šŸ”8264348440šŸ”
Model Call Girl in Narela Delhi reach out to us at šŸ”8264348440šŸ”
Ā 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
Ā 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
Ā 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
Ā 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
Ā 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
Ā 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
Ā 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
Ā 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
Ā 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
Ā 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
Ā 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
Ā 

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