Você está na página 1de 7

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:
(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

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 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

SEARCHING FOR A CHARACTER IN THE STRING

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:

NOP SCASB JNZ LOOP1 MOV [SI],BL INC SI

LOOP1:

INC BL LOOP LOOP2 INT 3

FIND AND REPLACE A CHARACTER IN THE STRING

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:

LOOP BACK INT 3

OUTPUT
COPYING A STRING INPUT MEMORY DATA

OUTPUT MEMORY DATA

SEARCHING FOR A CHARACTER IN THE STRING INPUT MEMORY DATA

OUTPUT MEMORY LOCATION DATA

FIND AND REPLACE A CHARACTER IN THE STRING

INPUT MEMORY DATA OUTPUT MEMORY DATA

RESULT

Você também pode gostar