String Instructions
String Instructions
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.
Syntax:
assembly
CopyEdit
MOVS
Example Explanation
MOVS Move the byte or word from the address pointed by SI to the address pointed by DI.
✔ Flags Affected:
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:
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).
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:
Syntax:
assembly
CopyEdit
STOS
Example Explanation
✔ Flags Affected:
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: