Link to home
Start Free TrialLog in
Avatar of 0xC0DEB07
0xC0DEB07

asked on

_asm call puts in VC++ 2005

Hello experts

I'm trying to use standart C functions from the VC inline assembler but the program crashes at run time.
Here is the code:

#include <stdio.h>

char hello[] = "Hello";

void main(void)
{  
      
   __asm
  {
        mov  eax, offset hello
        push eax
        call puts
        pop  ebx
  }
}

Links to good tutorials on inline assembler in VC would be appreciated too.
thanks in advance
Avatar of AlexFM
AlexFM

char hello[] = "Hello";

int _tmain(int argc, _TCHAR* argv[])
{
    __asm
    {
        mov         esi,esp
        push        offset hello
        call          dword ptr [puts]
        add          esp,4
    }

    return 0;
}

http://www.microsoft.com/msj/0298/hood0298.aspx

__asm block is copied from C++ code produced by compiler:

    puts(hello);
004113AE  mov         esi,esp
004113B0  push        offset hello (417000h)
004113B5  call        dword ptr [__imp__puts (4182B8h)]
004113BB  add         esp,4
Avatar of 0xC0DEB07

ASKER

Ok it works but what's with the mov esi, esp thing?

>>add esp, 4

That would be the stack clean up am I right?
thanks :)
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Lots of thanks AlexFM