well i going mad lol


i code this:


; Two strings are compared to equality
; ------------------------------------

%include "\lab\vasm\inc\nagoa.inc"





..start:

section data

String1 db "ola",0
String2 db "ola",0
StringSize equ $-String1 ;length of String

section code

mov esi,String1
mov edi,String2
mov ecx,StringSize+1
cld ; from left to right ...
repe cmpsb
jnz notcorrect
call MessageBoxA , NULL,"yes string are equal !","msg",MB_OK
xor eax,eax
ret

notcorrect:
call MessageBoxA , NULL,"string are NOT equal !","msg",MB_OK
xor eax,eax
ret




it says the strings are not equal ..... strange :(






then i tried this :

just compared the String1 with it self




; Two strings are compared to equality
; ------------------------------------

%include "\lab\vasm\inc\nagoa.inc"





..start:

section data

String1 db "ola",0
StringSize equ $-String1 ;length of String

section code

mov esi,String1
mov edi,String1
mov ecx,StringSize+1
cld ; from left to right ...
repe cmpsb
jnz notcorrect
call MessageBoxA , NULL,"yes string are equal !","msg",MB_OK
xor eax,eax
ret

notcorrect:
call MessageBoxA , NULL,"string are NOT equal !","msg",MB_OK
xor eax,eax
ret



and here it says String are equal . :)




i can not understand this :)



please help me !
Posted on 2004-02-24 06:46:30 by Nguga
Change
mov ecx,StringSize+1


to
mov ecx,StringSize


If I am not wrong.
Posted on 2004-02-24 06:49:10 by roticv
it is the same result ....

strange :(
Posted on 2004-02-24 06:52:18 by Nguga
Hi Nguga,

You have no idea what the state of the flags is when it exits the loop, just that it will not be equal. The only thing you can rely on is that if ECX = 0 then the strings are identical :

mov esi,String1

mov edi,String2
mov ecx,StringSize+1
cld ; from left to right ...
repe cmpsb
[color=red][b]or ecx,ecx[/b][/color]
jnz notcorrect
call MessageBoxA , NULL,"yes string are equal !","msg",MB_OK
xor eax,eax
ret

notcorrect:
call MessageBoxA , NULL,"string are NOT equal !","msg",MB_OK
xor eax,eax
ret
Posted on 2004-02-24 07:01:42 by donkey
Hi donkey :)



not working :(


strange !!!


that does not work ...


; Two strings are compared to equality
; ------------------------------------

%include "\lab\vasm\inc\nagoa.inc"





..start:

section data

String1 db "ola",0
String2 db "ola",0
StringSize equ $-String1 ;length of String

section code

mov esi,String1
mov edi,String2
mov ecx,StringSize
cld ; from left to right ...
repe cmpsb
or ecx,0
jnz notcorrect
call MessageBoxA , NULL,"yes string are equal !","msg",MB_OK
xor eax,eax
ret

notcorrect:
call MessageBoxA , NULL,"string are NOT equal !","msg",MB_OK
xor eax,eax
ret



it gives Strings are NOT equal :(
Posted on 2004-02-24 07:07:25 by Nguga
I don't believe that I used:

or ecx,0

I used:

or ecx,ecx

Also, I think you have this wrong:

String1 db "ola",0
String2 db "ola",0
StringSize equ $-String1

Should be :

String1 db "ola",0
String2 db "ola",0
StringSize equ $-String2
Posted on 2004-02-24 07:08:34 by donkey
strange i never thought that


StringSize equ $-String2

is diferent

StringSize eq $-String1

when they are equal ....



why ??

it works now !!

THANKS :)



; Two strings are compared to equality
; ------------------------------------

%include "\lab\vasm\inc\nagoa.inc"





..start:

section data

String1 db "ola",0
String2 db "ola",0
StringSize equ $-String2 ;length of String

section code

mov esi,String1
mov edi,String2
mov ecx,StringSize
cld ; from left to right ...
repe cmpsb
or ecx,ecx
jnz notcorrect
call MessageBoxA , NULL,"yes string are equal !","msg",MB_OK
xor eax,eax
ret

notcorrect:
call MessageBoxA , NULL,"string are NOT equal !","msg",MB_OK
xor eax,eax
ret
Posted on 2004-02-24 07:15:46 by Nguga
String1 db "ola",0
String2 db "ola",0
StringSize equ $-String2

$ is the current location counter.

they are different because in essence it is this:

StringSize equ (OFFSET StringSize - OFFSET String2) ; (= 4)

While the other is :

StringSize equ (OFFSET StringSize - OFFSET String1) ; (= 8)
Posted on 2004-02-24 07:25:25 by donkey

String1 db "ola",0
String2 db "ola",0
StringSize equ $-String2

$ is the current location counter.

they are different because in essence it is this:

StringSize equ (OFFSET StringSize - OFFSET String2) ; (= 4)

While the other is :

StringSize equ (OFFSET StringSize - OFFSET String1) ; (= 8)



Well since he is not doing the second one it's not the problem


Btw did you try lea instead of mov (edi/esi),string ??
Posted on 2004-02-24 10:06:15 by AceEmbler
Well since he is not doing the second one it's not the problem

Yes, it is a problem, he is comparing the first to the second. The length was wrong, he was scanning past the end of the strings.
Posted on 2004-02-24 10:11:30 by donkey


Yes, it is a problem, he is comparing the first to the second. The length was wrong, he was scanning past the end of the strings.


LOL i was reading code already corrected by you and did not know where did you take this StringSize equ (OFFSET StringSize - OFFSET String1) from :tongue: :stupid:
Posted on 2004-02-24 10:20:14 by AceEmbler