string manipulation
DESCRIPTION
assembly language program for performing the string manipulation operations in 8086 microprocessorstring can be manipulated on bit by bit AND , OR, NOT operationTRANSCRIPT
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.NO
ITEM SPECIFICATION QUANTITY
1. Microprocessor kit 8086 12 Key board 13 Power Supply +5 V dc 1
ALGORITHM:
(i) COPING A STRING
1. Initialize the data segment .(DS)2. Initialize the extra data segment .(ES)3. Initialize the start of string in the DS. (SI)4. Initialize the start of string in the ES. (DI)5. Move the length of the string (FF) in CX register.6. Move the byte from DS TO ES, till CX=0.
(ii) SEARCHING A STRING
1. Initialize the extra segment .(ES)2. Initialize the start of string in the ES. (DI)3. Move the number of elements in the string in CX register. 4. Move the byte to be searched in the AL register.5. Scan for the byte in ES. If the byte is found ZF=0, move the address pointed
by ES:DIto BX.
(iii) FIND AND REPLACE
1. Initialize the extra segment .(E S)2. Initialize the start of string in the ES. (DI)3. Move the number of elements in the string in CX register. 4. Move the byte to be searched in the AL register.5. Store the ASCII code of the character that has to replace the scanned byte
in BL register.6. Scan for the byte in ES. If the byte is not found, ZF≠1 and repeat
scanning.7. 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
Check NO for ZF=1
YES
Move the content ofBL to ES: DI
STOP
PROGRAM
COPYING A STRINGADDRESS 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 intodestination until count reaches zero
INT 3 Stop
SEARCHING FOR A CHARACTER IN THE STRINGADDRESS OPCODE LABEL 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
LOOP2: 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
LOOP1: INC BL Increment the relative address
LOOP LOOP2 Repeat until the count reaches zero
INT 3 Stop
FIND AND REPLACE A CHARACTER IN THE STRINGADDRESS OPCODE LABEL PROGRAM COMMENTS
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
LOOP1: LOOP BACK Continue until count zero.
INT 3 Stop
OUTPUT
COPYING A STRING
INPUT
MEMORYDATA
OUTPUT
MEMORY
DATA
SEARCHING FOR A CHARACTER IN THE STRING
INPUTMEMORYDATA
OUTPUTMEMORY LOCATIONDATA
FIND AND REPLACE A CHARACTER IN THE STRING
INPUTMEMORY
DATA
OUTPUT
MEMORY
DATA
RESULT