STRING MANIPULATION INSTRUCTIONS Set

Posted By on September 15, 2014


Download PDF
BRANCH INSTRUCTIONS Set
Flag manipulation and processor control instructions Set

STRING MANIPULATION INSTRUCTIONS


A series of data byte or word available in memory at consecutive locations, to be referred as byte string or word string. A string of characters may be located in consecutive memory locations, where each character may be represented by its ASCII equivalent.
The 8086 supports a set of more powerful instructions for string manipulations for referring to a string , two parameters are required.

  1. Starting and end address of a string
  2. length of a string.

The length of the string is usually stored as count in the CX register. The incrementing or decrementing of the pointer , in string instructions, depends upon the direction flag (DF) status. If it is a byte string operation, the index registers are updated by one . On the other hand , if it is a word string operation, the index registers are updated by two.

REP : Repeat Instruction Prefix
This instruction is used as a prefix to other instructions , the instruction to which the REP prefix is provided  is executed repeatedly until the CX register becomes zero (at each iteration the CX is automatically decremented by one).

  1. REPE / REPZ – Repeat operation while equal / zero.
  2. REPNE / REPNZ – Repeat operation while not equal / zero.

These are used for CMPS , SCAS instructions only as instruction prefixes.

MOVSB/ MOVSW : Move string byte or string word.
Suppose a string of bytes stored in a set of consecutive memory locations is to be moved to another set of destination locations. The starting byte of source string is located in the memory location whose address may be computed using SI and DS contents.
The starting address of the destination locations where this string has to be relocated is given by DI ( Destination Index) and ES (Extra segment) contents.
CMPS : Compare string byte or string word.
The CMPS instruction can be used to compare two strings of byte or words. The length of the string must be stored in the register CX. If both the byte or word strings are equal, zero flag is set.
The REP instruction prefix is used to repeat the operation till CX (counter) becomes zero or the condition specified by the REP prefix is false.
SCAN : Scan string byte or string word.
This instruction scans a string of bytes or words for an operand byte or word specified in the register AL or AX. The string is pointed to by ES:DI register pair. The length of the string is stored in CX. The DF controls the mode for scanning of the string.Whenever a match to the specified operand is found in the string, execution stops and the zero flag is set. If no match is found the zero flag is reset.
LODS : Load string byte or string word
The LODS instruction loads the AL / AX register by the content of a string pointed to by the DS : SI pair. The SI is modified automatically depending upon DF. If it is a byte transfer (LODSB), the SI is modified bu one and if its a word transfer (LODSW), the SI is modified by two. No other falgs are affected by the instruction.

STOS : Store string byte or string word.
The STOS instruction stores the AL /AX register contents to a location in the string pointed by the ES : DI pair . The DI is modified accordingly . No falgs are affected by this instruction .
The direction flag controls the string instruction execution. The SI and DI are modified after each iteration automatically. If DI = 1, then the execution follows auto decrement mode, SI and DI are decremented automatically after each iteration. IF DS = 0, then the execution follows auto increment mode. In this mode, SI and DI are incremented automatically after each iteration.

 

BRANCH INSTRUCTIONS Set
Flag manipulation and processor control instructions Set

Download PDF

Posted by Akash Kurup

Founder and C.E.O, World4Engineers Educationist and Entrepreneur by passion. Orator and blogger by hobby

Website: http://world4engineers.com