Code:
; Program to compare two string length
.MODEL SMALL
.STACK 100H
.DATA
STR1 DB 'CODING$'
STR2 DB 'ATHARV$'
L1 DB 0
L2 DB 0
RES DB ?
.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
CMP L1 , DL ; Comparing the length of str1 and str2
JE RE
MOV RES , 2 ; If string not equal then res 2
JMP EXIT
RE:
MOV RES , 1 ; If string equal then res 1
EXIT:
MOV DL , RES
MOV AH , 4CH ; Service routine for exit
INT 21H
END
; Program to compare two string length
.MODEL SMALL
.STACK 100H
.DATA
STR1 DB 'CODING$'
STR2 DB 'ATHARV$'
L1 DB 0
L2 DB 0
RES DB ?
.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
CMP L1 , DL ; Comparing the length of str1 and str2
JE RE
MOV RES , 2 ; If string not equal then res 2
JMP EXIT
RE:
MOV RES , 1 ; If string equal then res 1
EXIT:
MOV DL , RES
MOV AH , 4CH ; Service routine for exit
INT 21H
END