Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   Assembly, NEED GUIDANCE WITH REPE CMPSB (http://www.go4expert.com/forums/assembly-guidance-repe-cmpsb-t29805/)

worriednacho 7Sep2013 03:42

Assembly, NEED GUIDANCE WITH REPE CMPSB
 
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


xpi0t0s 7Sep2013 21:13

Re: Assembly, NEED GUIDANCE WITH REPE CMPSB
 
Does it make any difference if you start your code with CLD (clear direction flag)?

worriednacho 8Sep2013 16:06

Re: Assembly, NEED GUIDANCE WITH REPE CMPSB
 
Quote:

Originally Posted by xpi0t0s (Post 100002)
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 - 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



All times are GMT +5.5. The time now is 15:08.