i need help in comparing a string...

the program goes ... ask to input 2 string then compare it, if it is same or not...
my problem is that even it is not equal it will print equal...

i think the problem is in the compare section.

could someone share me the right code in comparing a string...

big help is appreciated....

begin:
        call erase
        call first_string
        call get_strng1
        call sec_string
        call get_strng2
        call compare
        int 20h

erase:
       mov ax,03h
       int 10h
       ret

first_string:
        mov ah,09h
        lea dx,string_one
        int 21h
        ret

get_strng1:
        mov ah,0ah
        lea dx,store_strng1
        int 21h
        ret

       
sec_string:
        mov ah,09h
        lea dx,string_two
        int 21h
        ret


get_strng2:
        mov ah,0ah
        lea dx,store_strng2
        int 21h
        ret
       
       
compare:
    mov si, offset store_strng1
    mov di, offset store_strng2
    cld
    mov cx,5
    repe cmpsb
    jl display_equal
    jg notequal
   
   
       
notequal:
        mov ah,09h
        lea dx,not_equal
        int 21h
        jmp display_back
     

display_equal:
        mov ah,09h
        lea dx,equal
        int 21h
        jmp display_back
     


display_back:

    mov dx,offset msg
    mov ah, 9       
    int 21h
    mov ah, 1  
    int 21h
    cmp al,'y'
    jne exit   
    jmp begin
    int 21h
   
exit:
    mov ah, 4ch
    int 21h


msg db 0ah,0dh, "Try Again [y/n] : $"

store_strng1 db 5 dup()
store_strng2 db 5 dup()

string_one db 0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,   "String 1: $"
string_two db 0a,0d,0d,0d,0d,0d,0d,0d,0d,0d,0d,   "String 2: $"

equal db 0a,0d,'The string is equal! $'
not_equal db 0a,0d,'The string is not equal! $'

Have you tried hard-coding two identical strings, calling 'compare' and checking the result?

What about two different strings?

What about strings of different length, or indeed not equal to 5 chars (a very speciifc case you would agree)

This article has been dead for over six months. Start a new discussion instead.