1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice


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

  1. worriednacho

    worriednacho New 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
        .model small
           mese    db "match!","$"
           mesne   db "mismatch!","$"
           v1 db "apple","$"
           v2 db "apple","$"
        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
        mov dx,offset mese
        mov ah,09h
        int 21h 
        mov ah,4ch
        int 21h
        main endp
        end main
  2. xpi0t0s

    xpi0t0s Mentor

    Does it make any difference if you start your code with CLD (clear direction flag)?
  3. worriednacho

    worriednacho New Member

    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
    mov ds,ax
    mov es,ax

Share This Page