I’m working in Visual Studio 2010 and here’s a little bit of code I’m having trouble with:
void main()
{
int x;
char c1[100]="cd";
char c2[100]="abcdef";
_asm {
lea edx,c2
lea ecx,c1
push edx
push ecx
call subsir
add esp, 8
mov x, eax
}
}
char subsir (char *c1, char *c2)
{
_asm {
mov ecx, c1
mov edx, c2
mov edi, 0
mov esi, 0
start: cmp [edx + edi], 0
je end
mov esi, 0
mov eax, [edx + edi]
cmp eax, [ecx + esi]
.....
This is the first part of a program that’s meant to compare 2 words.
The problem I am having is that when I do
mov eax, [edx + edi]
eax receives an adress and not the actual value.
I tested this by doing
cmp eax, 97
which should activate a JE instruction (97 being the ASCII code for ‘a’) But it doesn’t. If I do
cmp [edx + edi], 97
it does activate the JE jump.
I would be very grateful if you could tell me what am I doing wrong and how can I put the actual valuea in EAX instead of an adress.
No, it is actually reading the memory at [edx + edi]. Problem is that it is reading 32-bits at a time. Which is not okay, you are comparing string content. That requires comparing one byte at a time. Fix: