Professional Documents
Culture Documents
MOVS/MOVSB/MOVSD Instruction:
This instruction copies a byte or word or double word from a location
in the data segment to a location in the extra segment. The offset of the source
byte or word in the data segment must be in the (E)SI register. The offset of
the destination in the extra segment must be contained in the (E)DI register.
for multiple byte or multiple word or multiple double word moves a number of
elements to be moved is put in the CX register so that it can function as a
counter. After the byte or word or double word is moved (E)SI and (E)DI are
automatically adjusted to point to the next source and the next destination. If
the direction flag is 0, then (E)SI and (E)DI will be incremented by : ! for byte
move, 4 for double word move. If the DF is a 1,then (E)SI and (E)DI will be
decremented by :1 for byte move,2 for word move,4 for double word move,
MOVS affects no flags.
The way to tell the assembler whether to code the instruction for a byte
or word or double word move is to add a “B” or a “W” or “D” to the MOVS
mnemonic. MOVSB, for example,says move a string as byte.MOVSW says move
a string as word.
Examples:
CLD ;Clear Direction Flag to autoincrement SI and DI
MOV AX,00H
After move SI will be one greater than offset of last in source string. DI will be
one greater than offset of last byte of destination string. CX will be 0.
1|Pa ge
INS/INSB/INSW Instruction : Input String from I/O Port
The Ins instruction transfers a byte or, a word or a double word, data from an
input port, designated by the DX register into the memory location pointed by
ES:(E)DI.
The way to tell the assembler whether to code the instruction for a byte or
word or double word transfer is to add a “B” or a “W” or a “D” to the INS
mnemonic. INSB, for example, says transfer a string as byte as byte. INSW says
transfer a string as word.
It is important to note that INS instruction does not permit the port number
to be specified as an immediate value. The port number cam be addressed
through the DX register.
Examples:
;Point (E)DI at destination string
2|Pa ge
The way to tell the assembler whether to code the instruction for a byte or
word or double word transfer is to add a “B” or a “W” or a “D” to the OUTS
mnemonic. OUTSB, for example, says transfer a string as byte. OUTSW says
transfer a string as word.
It is important to note that OUTS instruction does not permit the port
number to the specified as an immediate value. The port number can be
addressed through the DX register.
Examples:
;Point (E)DI at destination string
CMPS/CMPSB/CMPSW/CMPSD Instruction:
MOV(E)SI,OFFSET F_STRING
MOV(E)DI,OFFSET S_STRING
STD ;DF set so (E)SI and (E)DI will auto increment after
;compare
SCAS/SCASB/SCASW/SCASD Instruction:
SCAS compares a string byte with a byte in AL or a string word with word in
AX or a string double word with double word in EAX. The instruction affects
the flags, but it does not change either the operand in AL or AX or EAX or the
operand in the string. The string to be scanned must be in the extra segment
4|Pa ge
and (E)DI must contain the offset of the byte or the word or the double word
to be compared.
Examples:
; Scan a text string of 80 characters
LODS/LODSB/LODSW/LODSD Instruction:
This instruction copies a byte from a string location pointed to by SI to AL,or
a word from a string location pointed to by SI to AX or a double word from a
string location pointed to by (E)SI to AX.. LODS does not affects any flags.
Examples:
CLD ; Clear direction flag so (E)SI is auto incremented
LODS S_STRING.
STOS/STOSB/STOSW/STOSD Instruction:
The STOS instruction copies a byte from AL or a word from AX or a double
word from EAX to a memory location in the extra segment. (E)DI is used to
hold the offset of the memory location in the extra segment. After the copy,
(E)DI is automatically incremented or decremented to point to the next string
5|Pa ge
element in memory. If the direction flag, DF, is cleared, then (E)DI will
automatically be incremented by one for a byte string or incremented by two
for a word string or incremented by four for a double word string. If the
direction flag is set, (E)DI will be automatically decremented by one for a byte
string or decremented by two for a word string or decremented by four for a
double word string. STOS does not affect any flags.
Examples:
REP/REPE/REPZ/REPNE/REPNZ Instruction:
REP is a prefix which is written before one of the string instructions. These
instructions repeat until specified condition exits.
Examples:
6|Pa ge