I have been searching and can't quite find how to call a C++ library function from masm. I would like to be able to call printf and system. Can anyone point me in the right direction?

Thanks

lets say we want to use the C library "stdio.h", we need to use the extern and call instructions. Like so:

extern _printf ;allows you to access the printf functions from stdio.h;
...
mov ecx,5
push ecx ;push ecx on the stack for stdio;
push YOURTEXT ;replace YOURTEXT respectively, this will pass the arguement to printf;
call printf ;calls the functionl;
...

you still have to call an interupt, but thats just a basic example, but now you have to compile the C/C++ library then link it to your assembly program. Alternativly you can use Inline Assembly inside your C++ code which is a bit easier especially when it comes to compiling.

For compiling it might be easiest to use GCC for both C and ASM, but keep in mind GCC accepts "main", not "_start".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.