Program in ASSEMBLY to Compare two strings – MASM 8086

Program in ASSEMBLY to Compare two strings – MASM 8086

;=========Macro for caluclate length of string======
LEN MACRO str
mov di,offset str
mov bl,0
L:
cmp [di],'$'
je ex
inc bl
inc di
LOOP L
ex:
ENDM
;====================================================
;=========MACRO for printing msg Argument (string)===
PRINT MACRO str
lea dx,str
mov ah,09h
int 21h
ENDM
;====================================================
org 100h
.stack 100h
.data
str1 db "a$"
str2 db "ahsan ali$"
strlen1 db 0
strlen2 db 0
.code
;==============Initilize DS=================
mov ax,@DATA
mov ds,ax
compare PROC
LEN str1
mov strlen1,bl
LEN str2
mov strlen2,bl
cmp strlen1,bl
je enter
jmp result:
;========Compare stirng character by character======
enter:
mov cl,al
lea di,str1
lea si,str2
check:
mov al,[si]
cmp [di],al
jne NotFound
loop check
;====================================================
endp
result:
r db 0dh,0ah,"String are not Equal...$"
mov dx,offset r
mov ah,09h
int 21h
ret
NotFound:
f db 0dh,0ah,"String are not Equal...$"
mov dx,offset f
mov ah,09h
int 21h
ret
mov ah,4ch
int 21h
ret

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s