[SDL] safe x-platform asm

Mat Hostetter mat at curl.com
Tue Aug 31 07:44:56 PDT 1999

>>>>> "Charlie_Robson" ==   <Charlie_Robson at scee.net> writes:

 Charlie_Robson> i wish to add an optimised asm blitter to a little
 Charlie_Robson> project i'm working on, and wish to retain SDL's
 Charlie_Robson> cross-platform ability. perhaps nasm is the way to
 Charlie_Robson> go? has anyone tried using nasm and visualc++?

To solve this problem, I did a horrible hack where I cast an array of
bytes to a function pointer and called it.  I wrote the code in
assembly language and ran a little tool to dump out the raw bytes.
This trick works on a variety of x86 C compilers, including MSVC and

Interestingly it crashes Intel's C compiler with an internal error,
probably trying to inline the array or something.  :-)  But if the
array is in a different file than the caller you should be OK.

One drawback to this technique is there's no portable way to specify
the alignment of the code, although you can get up to 8 byte alignment
by using a struct or union containing a "double".


More information about the SDL mailing list