0% found this document useful (0 votes)
15 views14 pages

Cap 9

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views14 pages

Cap 9

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

EC2003E COMPUTER ARCHITECTURE AND PROCESSORS

Monsoon 2024-25
String Instructions

• Set of instructions for handling blocks of data in the form of bytes


or words
• String is an array of data of the same type-character string/byte
string etc.
• Example operations:
• To move blocks (e.g: 100 words/bytes) of data in a particular memory area
to another area
• Compare two blocks of data for equality
• Search a data block for a particular data
Pre-requisites for using String Instructions

• Two segments are to be defined: DS is the source segment and ES


is the destination segment.
• SI and DI are the pointers to DS and ES respectively
• Special flag (Direction Flag – DF) is used to control the
increment/decrement of address
• Flag is set (DF=1)– pointer registers get automatically decremented
• Flag is reset (DF=0)– pointer registers get automatically incremented
• Counter CX is used to count the number of operations
MOVS/MOVSB/MOVSW
• Copies a byte or word from a location in the data segment to a
location in the extra segment.
• The offset of the source in the data segment in the SI register.
• The offset of the destination in the extra segment in the DI register.
• For multiple byte or multiple word moves the number of elements to
be moved is put in the CX register.
• After the byte or word is moved SI and DI are automatically adjusted
to point to the next source and the next destination.
• If the direction flag is 0, then SI and DI will be incremented by 1 after a byte
move and they will incremented by 2 after a word move.
• If the DF is 1, then SI and DI will be decremented by 1 after a byte move and
they will be decremented by 2 after a word move. MOVS affects no flags.
MOVS/MOVSB/MOVSW - Example
CMPS/CMPSB/CMPSW
• The CMPS instruction can be used to compare a byte/word in one
string with a byte/word in another string
• SI is used to hold the offset of a byte/word in the source string and DI
is used to hold the offset of a byte/word in the other string.
• The comparison is done by subtracting the byte/word pointed to by
DI from the byte/word pointed to by SI.
• The AF, CF, OF, PF, SF, and ZF flags are affected by the comparison,
but neither operand is affected.
CMPS/CMPSB/CMPSW - Example
SCAS/SCASB/SCASW
• SCAS compares a string byte with a byte in AL or a string word with
word in AX.
• The instruction affects the flags, but it does not change either the
operand in AL (AX) or the operand in the String Instruction in 8086.
• The string to be ‘scanned must be in the extra segment and DI must
contain the offset of the byte or the word to be compared.
• After the comparison DI will be automatically incremented or
decremented according to direction flag, to point to the next element
in the two strings
• SCAS affects the AF, CF, OF, PF, SF and ZF flags.
SCAS/SCASB/SCASW-Example
LODS/LODSB/LODSW

• 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.
• LODS does not affect any flags. LODSB copies byte and LODSW copies
a word.
STOS/STOSB/STOSW

• The STOS instruction copies a byte from AL or a word from AX to a


memory location in the extra segment.
Procedures
• There may be a need to perform the same set of task again and again.
• Instead of writing the same sequence of instructions, again and again,
they are written separately in a subprogram.
• This subprogram is called a procedure.
• Whenever we need to execute the instructions mentioned in the
procedure, we can simply make a CALL to it.
• The duplication in the instructions can be avoided.
Procedures
Steps taken to execute Procedures
• Saves the current IP content in the stack
• IP is loaded with the address of the procedure (From CALL
instruction)
• Procedure is executed until RET instruction
• Old value of IP is retrieved from the stack and the control returns to
the main program

You might also like