EXPT NO:
DATE: STRING MANIPULATION OPERATIONS IN 8086 MICROPROCESSOR
AIM:
To write the assembly language program for performing the string manipulation operations in 8086 microprocessor APPARATUS REQUIRED: SL.N O 1. 2 3
ITEM Microprocessor kit Key board Power Supply
SPECIFICATION 8086 +5 V dc
QUANTITY 1 1 1
ALGORITHM: COPING A STRING
(i)
1. 2. 3. 4. 5. 6. (ii)
Initialize the data segment .(DS) Initialize the extra data segment .(ES) Initialize the start of string in the DS. (SI) Initialize the start of string in the ES. (DI) Move the length of the string (FF) in CX register. Move the byte from DS TO ES, till CX=0. SEARCHING A STRING
1. 2. 3. 4. 5.
(iii)
Initialize the extra segment .(ES) Initialize the start of string in the ES. (DI) Move the number of elements in the string in CX register. Move the byte to be searched in the AL register. Scan for the byte in ES. If the byte is found ZF=0, move the address pointed by ES:DIto BX. FIND AND REPLACE
1. 2. 3. 4. 5. 6. 7.
Initialize the extra segment .(E S) Initialize the start of string in the ES. (DI) Move the number of elements in the string in CX register. Move the byte to be searched in the AL register. Store the ASCII code of the character that has to replace the scanned byte in BL register. Scan for the byte in ES. If the byte is not found, ZF≠1 and repeat scanning. If the byte is found, ZF=1.Move the content of BL register to ES:DI.
FLOWCHART
COPING A STRING START
Initialize DS, ES, SI, DI
CX=length of string, DF=0.
Move a byte from source string (DS) to destination string (ES)
Decrement CX
Check for ZF=1 NO YES
STOP
SEARCHING A STRING
START
Initialize DS, ES, SI, DI
CX=length of the string, DF=0.
Scan for a particular character specified in AL Register.
NO Check for ZF=1
YES
Move DI to BX
STOP
FIND AND REPLACE START
Initialize DS, ES, SI, DI
CX=length of the string in ES, DF=0.
Scan for a particular character specified in AL
NO
Check for ZF=1 YES Move the content of BL to ES: DI
STOP
PROGRAM COPYING A STRING
ADDRESS OPCODE
LABEL
PROGRAM COMMENTS MOV SI,1200H
Initialize destination address
MOV DI,1300H
Initialize starting address
MOV CX,0006H
Initialize array size
CLD
Clear direction flag
REP MOVSB
Copy the contents of source into destination until count reaches zero Stop
INT 3
SEARCHING FOR A CHARACTER IN THE STRING
ADDRESS OPCODE
LABEL
LOOP2:
LOOP1:
PROGRAM
COMMENTS
MOV DI,1300H
Initialize destination address
MOV SI, 1400H
Initialize starting address
MOV CX, 0006H
Initialize array size
MOV BL,00H
Initialize the relative address
CLD
Clear direction flag
MOV AL, 08H
Store the string to be searched
NOP
Delay
SCASB
Scan until the string is found
JNZ LOOP1
Jump if the string is found
MOV [SI],BL
Move the relative address to SI.
INC SI
Increment the memory pointer
INC BL
Increment the relative address
LOOP LOOP2
Repeat until the count reaches zero
INT 3
Stop
FIND AND REPLACE A CHARACTER IN THE STRING
ADDRESS
OPCODE LABEL
PROGRAM
LOOP1:
MOV DI,1300H
Initialize starting address
MOV CX, 0006H
Initialize array size
CLD
Clear direction flag
MOV AL, 08H
Store the string to be searched
MOV BH,30H
Store the string to be replaced
BACK:SCASB
Scan until the string is found
JNZ LOOP1
Is the string found
DEC DI
Decrement the destination address
MOV [DI],BL
Replace the string
LOOP BACK
Continue until count zero.
INT 3
Stop
OUTPUT COPYING A STRING INPUT MEMORY DATA
OUTPUT MEMORY DATA
SEARCHING FOR A CHARACTER IN THE STRING INPUT MEMORY DATA
OUTPUT MEMORY LOCATION DATA
COMMENTS
FIND AND REPLACE A CHARACTER IN THE STRING
INPUT MEMORY DATA OUTPUT MEMORY DATA
RESULT