Assembly, NEED GUIDANCE WITH REPE CMPSB

Discussion in 'Assembly Language Programming (ALP) Forum' started by worriednacho, Sep 6, 2013.

  1. worriednacho

    worriednacho New Member

    Joined:
    Sep 6, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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
    
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Does it make any difference if you start your code with CLD (clear direction flag)?
     
  3. worriednacho

    worriednacho New Member

    Joined:
    Sep 6, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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 - ES:DI ..

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

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice