Using array in x86 inline assembly?

I have a method (C ++) that returns a character and takes an array of characters as parameters.

This is the first time I enter the assembly and just try to return the first character of the array to the dl register. Here is what I still have:

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 ♀

Any idea what is going on? Thanks

+2
source share
2 answers

Assembly line:

mov eax, arrayOfLetters[0]

moves the pointer to an array of characters in eax(note that not what it arrayOfLetters[0]will do in C, but the assembly is not C).

You will need to add immediately afterwards to make the small build process:

mov al, [eax]
+4
source

:

char returnFirstChar( const char arrayOfLetters[] )
{
    char max;
    __asm
    {
         mov eax, arrayOfLetters ; Move the pointer value of arrayOfLetters into eax.
         mov dl, byte ptr [eax]  ; De-reference the pointer and move the byte into eax.
         mov max, dl             ; Move the value in dl into max.
    }
    return max;
}

, , .

:

1) , , MSVC .
2) edx X'oring dl 0. . , , dl, .

+4

Source: https://habr.com/ru/post/1741368/