Escolar Documentos
Profissional Documentos
Cultura Documentos
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:
(i)
COPING A STRING 1. 2. 3. 4. 5. 6. 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
(ii)
1. 2. 3. 4. 5.
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
(iii)
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, ZF1 and repeat scanning. If the byte is found, ZF=1.Move the content of BL register to ES:DI.
FLOWCHART
COPING A STRING
START
Decrement CX
STOP
SEARCHING A STRING
START
YES
Move DI to BX
STOP
NO
STOP
PROGRAM
COPYING A STRING
ADDRESS OPCODE
LABEL
PROGRAM COMMENTS MOV SI,1200H MOV DI,1300H MOV CX,0006H CLD REP MOVSB INT 3 Initialize destination address Initialize starting address Initialize array size Clear direction flag Copy the contents of source into destination until count reaches zero Stop
ADDRESS OPCODE
LABEL
PROGRAM
MOV DI,1300H MOV SI, 1400H MOV CX, 0006H MOV BL,00H CLD MOV AL, 08H
COMMENTS Initialize destination address Initialize starting address Initialize array size Initialize the relative address Clear direction flag Store the string to be searched Delay Scan until the string is found Jump if the string is found Move the relative address to SI. Increment the memory pointer Increment the relative address Repeat until the count reaches zero Stop
LOOP2:
LOOP1:
ADDRESS
OPCODE LABEL
PROGRAM
MOV DI,1300H MOV CX, 0006H CLD MOV AL, 08H MOV BH,30H BACK:SCASB JNZ LOOP1 DEC DI MOV [DI],BL
COMMENTS Initialize starting address Initialize array size Clear direction flag Store the string to be searched Store the string to be replaced Scan until the string is found Is the string found Decrement the destination address Replace the string Continue until count zero. Stop
LOOP1:
OUTPUT
COPYING A STRING INPUT MEMORY DATA
RESULT