Assembly, NEED GUIDANCE WITH REPE CMPSB

worriednacho's Avatar, Join Date: Sep 2013
Newbie Member
the repe cmpsb is confusing me a bit. i know very well that repe cmpsb will compare string bytewise until equal or cx=0 .. BUT when i try to confirm this with a simple program, no matter whether the strings are equal or not, i always get a mismatch.
can anyone please guide me and explain what i am doing wrong.. would be a great help
"i am comparing two strings v1 & v2 both having the string 'apple', the answer however results in mismatch" Here is the code
Code:
    .model small
    .data
       mese    db "match!","$"
       mesne   db "mismatch!","$"
       v1 db "apple","$"
       v2 db "apple","$"
    .code
    main proc
    mov ax,@data
    mov ds,ax   
    
    mov si,offset v1
    mov di,offset v2
    
    mov cx,5
    
    repe cmpsb
    je equal
    
    mov dx,offset mesne
    jmp print
    equal:
    mov dx,offset mese
    print:
    mov ah,09h
    int 21h 
    
    mov ah,4ch
    int 21h
    
    main endp
    end main
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Does it make any difference if you start your code with CLD (clear direction flag)?
0
worriednacho's Avatar, Join Date: Sep 2013
Newbie Member
Quote:
Originally Posted by xpi0t0s View Post
Does it make any difference if you start your code with CLD (clear direction flag)?
cld just clears the direction flag.. and i found out why my program is problematic. the issue is that the cmpsb needs the extra segment. ES:SI - ESI ..

the only addition to make this code perfect is adding mov es,ax after mov ds,ax
Code:
mov ds,ax
mov es,ax