Using asm functions in C code

Started by The_Grey_Beast, March 25, 2005, 11:42:37 AM

Previous topic - Next topic

The_Grey_Beast

Hey everybody,

I wrote a lot of asm functions using the inline assembler, and most of them store the parameters in registers. For example, the function font_printc() prints a character to the screen (not the console, but a DirectDraw Surface). The algorithm it uses is very complicated (because the font format I use is very hard). The main thing is that this function needs a parameter (the character to print), but it expects it in the al register. For example, to call the function you'll have to use:

mov al, charToPrint
call font_printc


But I don't know how can I do this in VC++ (to call the function from C code). The normal function calling conventions (__cdecl, __fastcall, __stdcall) are of no use to me. How can I instruct the compiler that parameter1 is in al? I know I 'could' use a macro:

#define font_printc(c) __asm \
{ \
__asm mov al, c \
__asm call __font_printc \
}


I know this will work, but will affect optimization in several ways (first, because the compiler will avoid register variable storage for my macro). Is there a command or something I should do to instruct the compiler to store parameter1 in al (or any register I want to)? Please, I can't afford any performance loss.

Thanks.
The_Grey_Beast

PellesC

AFAIK it's impossible. You either use the normal calling conventions or an __asm block. Now other way to safely target a specific register.

Pelle