I have a method (C++) that returns a character and takes an array of characters as its parameters.
I'm messing with assembly for the first time and just trying to return the first character of the array in the dl register. Here's what I have so far:
char returnFirstChar(char arrayOfLetters[])
{
char max;
__asm
{
push eax
push ebx
push ecx
push edx
mov dl, 0
mov eax, arrayOfLetters[0]
xor edx, edx
mov dl, al
mov max, dl
pop edx
pop ecx
pop ebx
pop eax
}
return max;
}
For some reason this method returns a ♀
Any idea whats going on? Thanks
The line of assembly:
is moving a pointer to the array of characters into
eax
(note, that's not whatarrayOfLetters[0]
would do in C, but assembly isn't C).You'll need to add the following right after it to make your little bit of assembly work:
Well here is how I'd write that function:
That seems to work perfectly.
Notes:
1) As I said in my comment you don't need to push the registers on the stack, let MSVC handle that.
2) Don't bother clearing edx by X'oring it against it self or don't set dl to 0. Both will achieve the same thing. All in you don't even need to do that as you can just overwrite the value stored in dl with your value.