1
votes

I have problems with inline assembly in visual c++ 2010 Ultimate (Windows 7 Professional). All my inline assemblies don't work, when I use chars, DWORD strings etc etc... So I copied this code from MSDN in my console application:

// InlineAssembler_Calling_C_Functions_in_Inline_Assembly.cpp
// processor: x86
#include <stdio.h>

char format[] = "%s %s\n";
char hello[] = "Hello";
char world[] = "world";
int main( void )
{
   __asm
   {
      mov  eax, offset world
      push eax
      mov  eax, offset hello
      push eax
      mov  eax, offset format
      push eax
      call printf
      //clean up the stack so that main can exit cleanly
      //use the unused register ebx to do the cleanup
      pop  ebx
      pop  ebx
      pop  ebx
   }
}

I have nothing except those lines in my application, result: The string doesn't get printed and the application crashs. Any ideas why this happens?

2

2 Answers

1
votes

Project + Properties, C/C++, Code Generation, select /MTd. Repeat for the Release configuration, select /MT.

If you want to make it work with the non-static version of the CRT then you'll need to write the call like this:

  call dword ptr printf

Exports from a DLL need to be called indirectly.

0
votes

I am assuming that popping into ebx is the reason. It is Your responsibility to maintain the integrity of all registers, excluding eax. Try popping into eax instead.