I made this 8086 assembly program for string comparison, but it contains an infinite loop. I have checked and rechecked. Can anyone find where i am wrong?
org 100
jmp start
str1: db "hello$"
str2: db "ello$"
start:
lea bx,str1
mov si,bx
lea ax,str2
mov di,ax
mov ax,1234
jmp compare
compare:
mov bl,[si]
cmp [di],bl
jne notequal
cmp bx,'$'
je equal
inc si
inc di
jmp compare
notequal:
mov ax,0000h
hlt
equal:
mov bx,0001h
hlt
ret
I don’t know what you checked and rechecked, but you’re reading bytes from one of the strings into
bland yet comparing the entirebxwith ‘$’ instead of comparingblwith ‘$’.Did you consider debugging your code???
Also I don’t know why you use
hlt. If interrupts are disabled, your program will never return.Finally, if this is a .COM program for DOS, there’s a “little” difference between
org 100andorg 100h.