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
C++

Avatar of undefined
Last Comment
0xC0DEB07

8/22/2022 - Mon
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
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
AlexFM

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
0xC0DEB07

ASKER
Lots of thanks AlexFM
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23