0% found this document useful (0 votes)
2 views

EXPERIMENT NUMBER 8

This document describes an assembly language program that compares two strings using macros in MASM. It outlines the algorithm for string comparison, including initialization, input, length comparison, and character-by-character comparison. The program concludes by displaying whether the strings are equal or unequal.

Uploaded by

waghjayesh07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

EXPERIMENT NUMBER 8

This document describes an assembly language program that compares two strings using macros in MASM. It outlines the algorithm for string comparison, including initialization, input, length comparison, and character-by-character comparison. The program concludes by displaying whether the strings are equal or unequal.

Uploaded by

waghjayesh07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NUMBER :8

TITLE :

Write an Assembly Language Program to compare two strings.(Using MACRO)

Software required: MASM (Macro Assembler from Microsoft Corp.)

MACRO:

A macro is a group of instructions used repeatedly in the source code to perform a task. When the
repeated group of instructions is too short, not appropriate to be defined as procedure, macros are used.

The basic format of macro is

Macro name MACRO ; Define macro


………….. ; Body of macro
ENDM ; End of macro

Algorithm:

1. Initialize the Data segment


2. Allocate the data memory to save the strings
3. Initialize the DS and ES registers
4. Accept the first string
5. Accept the second string
6. Compare the lengths of the two strings. If not equal go to step 11
7. Load number of characters to be compared in CX register
8. Compare the strings, character by character. If not same, go to step 11
9. Print “Equal strings”
10. Go to step 12
11. Print “Unequal string”
12. Stop
Start

Prompt to enter first string

Read the string in BUFF1,CL=Length of string 1

Prompt to enter second string

Read the string in BUFF2,CH=Length of string 2

N
Is CH = CL

SI= Start address of BUFF1, DI=Start address of BUFF2

CX=Length of strings , DF=0

IS [SI]=[DI]

SI=SI+1, DI=DI+1, CX=CX-1

N
Is CX = 0 ?

Print “Equal strings”

Print “Unequal strings”

Stop
PROGRAM:

PRINT MACRO MES ; Macro to display string

MOV AH,09H

LEA DX, MES

INT 21H

ENDM

.MODEL SMALL

.DATA

MS1 DB 10,13,”ENTER FIRST STRING:$”

MS2 DB 10,13,”ENTER SECOND STRING:$”

MS3 DB 10,13,”EQUAL STRINGS$”

MS4 DB 10,13,”UNEQUAL STRINGS$”

BUFF1 DB 10 DUP(‘$’)

BUFF2 DB 10 DUP(‘$’)

.CODE

MOV AX,@DATA

MOV DS,AX

MOV ES,AX

PRINT MS1

MOV AH, 0AH

LEA DX, BUFF1

INT 21H

PRINT MS2

MOV AH, 0AH

LEA DX, BUFF2

INT 21H
MOV CL, LENGTH BUFF1

MOV CH, LENGTH BUFF2

CMP CL,CH

JNE UNEQ

MOV CH,00H

LEA SI, BUFF1

LEA DI, BUFF2

CLD

REPE CMPSB

JNZ UNEQ

PRINT MS3

JMP FINISH

UNEQ: PRINT MS4

FINISH: MOV AH, 4CH

INT 21H

END

Conclusion:

This program check whether the strings are equal or not and display a message “ Equal strings” or
“unequal strings” on screen.

You might also like