0

How do I achieve something like this:

abc db "abc",0
def db "def",0
textnotequal db "strings are not equal",0
textequal db "strings are equal",0

 .if abc != def
    invoke MessageBox, NULL, addr textnotequal, addr textnotequal, MB_OK

 .elseif abc == def
     invoke MessageBox, NULL, addr textequal, addr textequal, MB_OK
 .endif

Do I need to mov abc & def into something first or is this generally not possible ?

Marius Prollak
  • 368
  • 1
  • 7
  • 22
  • `abc` and `def` are pointers to strings, not the strings themselves. By comparing them you are comparing different addresses of memory, and unless they point to the same place they are different, even if the strings they are pointing to are equal. In order to compare the strings you have to access those addresses and make a deeper comparasion byte by byte between each in order to know if the strings are equal or not. You may need to write a function for that. – Havenard Oct 19 '13 at 17:47
  • Exactly, I wrote an example of such a function below using simple repe cmpsb line for the deeper comparison. – Igor Popov Oct 19 '13 at 17:54

1 Answers1

0

You can write your version of cmpstr function in assembly. For example:

abc db "abc",0
def db "def",0
...
mov ecx,3     #the length of the abc and def strings
cld           #set the direction flag so that EDI and ESI will increase using repe
mov esi, offset [abc]  #moves address of abc string into esi
mov edi, offset [def]  #exact syntax may differ depending on assembler you use
                       #I am not exactly sure what MASM accepts but certainly something similar to this
repe cmpsb     #repeat compare [esi] with [edi] until ecx!=0 and current chars in strings match
               #edi and esi increase for each repetition, so pointing to the next char
cmp ecx,0      #test if the above command passed until the end of strings
je strings_are_equal  #if yes then strings are equal
# here print the message that strings are not equal (i.e. invoke MessageBox)
jmp end
strings_not_equal:
# here print the message that strings are equal (i.e. invoke MessageBox)
end:
Igor Popov
  • 2,588
  • 17
  • 20