An __asm block can call C functions, including C library routines. The following example calls the printf library routine:
#include <stdio.h>char format[] = "%s %s\n";char hello[] = "Hello";char world[] = "world";void main( void ){__asm {mov eax, offset worldpush eaxmov eax, offset hellopush eaxmov eax, offset formatpush eaxcall printf// clean up the stack so that main can exit cleanly// use the unused register ebx to do the cleanuppop ebxpop ebxpop ebx}}
Because function arguments are passed on the stack, you simply push the needed argumentsstring pointers, in the previous examplebefore calling the function. The arguments are pushed in reverse order, so they come off the stack in the desired order. To emulate the C statement
printf( format, hello, world );
the example pushes pointers
to world, hello, and format,
in that order, and then calls printf.
Shamelessly grepped
from MSDN
Last Updated by Jeff, 04-29-2000