Write a 8086 assembly language program to find whether two strings are of equal length. 5m Dec2005

By | November 4, 2014

Write a program in 8086 assembly language to find whether two strings are of equal length. You can assume that the strings are stored in the main memory and a string is terminated by a $ character 5m Dec2005

DATA SEGMENT
STR1 DB ‘GANGADHAR$’
STR2 DB ‘KOPELLA$’
MSG1 DB 10,13,’LENGTH OF THE STRING 1 IS :- $’
MSG2 DB 10,13,’LENGTH OF THE STRING 2 IS :- $’
MSG3 DB 10,13,’STRING ARE OF EQUAL LENGTH$’
MSG4 DB 10,13,’STRING ARE OF NOT EQUAL LENGTH$’
LEN1 DB 0H
LEN2 DB 0H
DATA ENDS

DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

LEA SI,STR1
NEXT1:
CMP [SI],’$’
JE DONE1
INC LEN1
INC SI
JMP NEXT1
DONE1:
DISPLAY MSG1

MOV AL,LEN1
ADD AL,30H

MOV DL,AL
MOV AH,2
INT 21H

LEA DI,STR2
NEXT2:
CMP [DI],’$’
JE DONE2
INC LEN2
INC DI
JMP NEXT2
DONE2:
DISPLAY MSG2

MOV AL,LEN2
ADD AL,30H

MOV DL,AL
MOV AH,2
INT 21H

MOV AL,LEN1
CMP AL,LEN2
JE EQUAL

DISPLAY MSG4
JMP EXIT
EQUAL:
DISPLAY MSG3

EXIT:
MOV AH,4CH
INT 21H
CODE ENDS

END START

 

DATA SEGMENT
STR1 DB 'GANGADHAR$'
STR2 DB 'KOPELLA$'
MSG1 DB 10,13,'LENGTH OF THE STRING 1 IS :- $'
MSG2 DB 10,13,'LENGTH OF THE STRING 2 IS :- $'
MSG3 DB 10,13,'STRING ARE OF EQUAL LENGTH$'
MSG4 DB 10,13,'STRING ARE OF NOT EQUAL LENGTH$' 
LEN1 DB 0H
LEN2 DB 0H 
DATA ENDS
 
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
 
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX 
 
LEA SI,STR1
NEXT1: 
CMP [SI],'$'
JE DONE1
INC LEN1
INC SI
JMP NEXT1 
DONE1: 
DISPLAY MSG1
 
MOV AL,LEN1
ADD AL,30H
 
MOV DL,AL
MOV AH,2
INT 21H
 
LEA DI,STR2
NEXT2: 
CMP [DI],'$'
JE DONE2
INC LEN2
INC DI
JMP NEXT2 
DONE2: 
DISPLAY MSG2
 
MOV AL,LEN2
ADD AL,30H
 
MOV DL,AL
MOV AH,2
INT 21H
 
MOV AL,LEN1
CMP AL,LEN2
JE EQUAL
 
DISPLAY MSG4
JMP EXIT
EQUAL: 
DISPLAY MSG3 
 
EXIT:
MOV AH,4CH
INT 21H
CODE ENDS
 
END START

 

Screen Shots :-

Asm_program_String_Equal_Length

 

Output After Execution :-

 

Asm_program_String_Equal_Length_Output