I am coding this program in 16 bit TASM and i seem to be having problems with CMPSB, the program first waits for the user to enter two strings and then compare them and see if they are equal or not, but it always recognize them as equal

Can anybody tell me what i am doing wrong ?

Posted on 2006-02-11 02:23:51 by XCHG

?  ?  ;Find the bigger length
?  ?  MOV CL , LEN1
?  ?  CMP CL , LEN2
?  ?  JG @@Compare
?  ?  MOV CL , LEN2


Well, first off, if the strings aren't the same length, then they aren't the same... try something like...


    ;Find the bigger length
    MOV CL , LEN1
    CMP CL , LEN2
    JNE @@NotEqual
    MOV CL , LEN2


?  ? 
?  ?  @@Compare:
?  ?  ;Now compare the strings
?  ?  XOR CH , CH
?  ?  CLD
?  ?  LEA DI , Str1Buffer
?  ?  LEA SI , Str2Buffer
?  ?  REP CMPSB
?  ?  JNE @@NotEqual


Personally,  I detest REP CMPSx instructions all together, try something like...


    @@Compare:
    ;Now compare the strings
    XOR CH , CH
    LEA DI , Str1Buffer
    LEA SI , Str2Buffer
    @@Loop:
    MOV AL, ; store byte from Str2Buffer into AL
    INC SI ; move your index to the next byte in the Str2Buffer
    MOV AH, ; store byte from Str1Buffer into AH
    INC DI ; move your index to the next byte in Str1Buffer
    CMP AH, AL ; compare the two bytes
    JNE @@NotEqual ; if they are not equal, then jump to our not equal message
    DEC CL ; otherwise decrement our length
    CMP CL, 0 ; if the length is not zero, the we haven't reached the end yet.
    JNE @@Loop ; otherwise just fall through into our equal message


Note the syntax I use here might not be right for TASM, I've not used TASM in many years and I'm not familiar with the coding style anymore. None the less I hope this helps you out.

Regards,
Bryant Keller
Posted on 2006-02-12 21:12:56 by Synfire
lol i cant believe i made such mistake in comparing strings with different lengths. and btw thanks for the help. appreciate it.
Posted on 2006-02-14 19:46:37 by XCHG
no worries, that's what I come here for ... okay so I really come here to take a break from EvilHomer2k's narcissistic deamanding of project completions, but at least it's productive. ;)
Posted on 2006-02-15 14:57:41 by Synfire