I’m trying to compare 2 strings to see if they’re equal in assembly. Case sensitive. They’re passed in from a cpp wrapper. Here is what I have so far:
I stored one string in esi, the other in edi:
LOOP:
mov al, [esi + edx*4]
mov bl, [edi + edx*4]
sub al, bl
INC edx
je LOOP
jmp END_LOOP ; if it's not equal, do some stuff at the end
END_LOOP:
What am I doing wrong? How does it know when I’m at the end of a char array?
Since these strings are C++ strings, and I’m guessing they are made of
chars and not wide characters, then each character is one byte in size so you should not be multiplying the index registeredxby 4. Also, you cannot incrementedxbefore immediately before yourjeinstruction, because that only jumps is edx has been bumped to zero.Finally, the strings end with a 0 byte. So you are looking for either
alorblto be zero to know when to stop your loop.You can modify your code along these lines:
However I suggest just doing a search for string comparison in x86. There is a
cmpsinstruction. You can even arrange to call thestrncmpfunction if you like. There are several ways to go about this.