Code:
; Program to compare two string with contain
.MODEL SMALL
.STACK 100H
.DATA
STR1 DB 'CODING$'
STR2 DB 'ATHARV$'
L1 DB 0
L2 DB 0
MSG1 DB 'Strings are Same $'
MSG2 DB 'Strings are not Same $'
.CODE
MOV AX , @DATA ; Initializing Data Segment
MOV DS , AX
; Counting length of STR1
MOV DL , 0
MOV SI , OFFSET STR1 ; Storing base address of STR1
UP1:
MOV AL , [SI]
CMP AL , '$' ; Compare end of string
JE DN1 ; Jump If Equal
INC DL
INC SI
JMP UP1 ; Jump to UP1
DN1:
MOV L1 , DL ; Storing Result
; Counting length of STR2
MOV DL , 0
MOV SI , OFFSET STR2 ; Storing base address of STR2
UP2:
MOV AL , [SI]
CMP AL , '$' ; Compare end of string
JE DN2 ; Jump If Equal
INC DL
INC SI
JMP UP2 ; Jump to UP2
DN2:
MOV L2 , DL ; Storing Result
; Comparing the length of str1 and str2
CMP L1 , DL
JE RE
JMP EXIT2 ; If string not equal
RE:
; Comparing String Based on Contains
MOV CL , L1 ; Initializing Loop Counter
MOV SI , OFFSET STR1
MOV DI , OFFSET STR2
UP:
MOV AL , [SI]
MOV DL , [DI]
CMP DL , AL
JNE EXIT2 ; Jump If Not Equal
INC SI
INC DI
LOOP UP
; String Same
EXIT1:
LEA DX , MSG1
MOV AH , 09H
INT 21H
JMP EXIT
; String Not Same
EXIT2:
LEA DX , MSG2
MOV AH , 09H
INT 21H
EXIT:
MOV AH , 4CH ; Service routine for exit
INT 21H
END
; Program to compare two string with contain
.MODEL SMALL
.STACK 100H
.DATA
STR1 DB 'CODING$'
STR2 DB 'ATHARV$'
L1 DB 0
L2 DB 0
MSG1 DB 'Strings are Same $'
MSG2 DB 'Strings are not Same $'
.CODE
MOV AX , @DATA ; Initializing Data Segment
MOV DS , AX
; Counting length of STR1
MOV DL , 0
MOV SI , OFFSET STR1 ; Storing base address of STR1
UP1:
MOV AL , [SI]
CMP AL , '$' ; Compare end of string
JE DN1 ; Jump If Equal
INC DL
INC SI
JMP UP1 ; Jump to UP1
DN1:
MOV L1 , DL ; Storing Result
; Counting length of STR2
MOV DL , 0
MOV SI , OFFSET STR2 ; Storing base address of STR2
UP2:
MOV AL , [SI]
CMP AL , '$' ; Compare end of string
JE DN2 ; Jump If Equal
INC DL
INC SI
JMP UP2 ; Jump to UP2
DN2:
MOV L2 , DL ; Storing Result
; Comparing the length of str1 and str2
CMP L1 , DL
JE RE
JMP EXIT2 ; If string not equal
RE:
; Comparing String Based on Contains
MOV CL , L1 ; Initializing Loop Counter
MOV SI , OFFSET STR1
MOV DI , OFFSET STR2
UP:
MOV AL , [SI]
MOV DL , [DI]
CMP DL , AL
JNE EXIT2 ; Jump If Not Equal
INC SI
INC DI
LOOP UP
; String Same
EXIT1:
LEA DX , MSG1
MOV AH , 09H
INT 21H
JMP EXIT
; String Not Same
EXIT2:
LEA DX , MSG2
MOV AH , 09H
INT 21H
EXIT:
MOV AH , 4CH ; Service routine for exit
INT 21H
END