Advertisement Jump to content
Sign in to follow this  

Compile assembly language in VC++ 2003?

This topic is 4674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


void MyFunction() {
__asm { instructions };

Note that it is generally considered bad practice.

Is there a reason you want to do this?

If your goal is simply to learn asm, then good luck to you. It can be exciting to learn the details of how things work.

If your goal is to try to optimize code, then don't bother. The compiler writers have spent years studying, learning, and documenting how to generate and optimize the output. The things you write in your asm block are not optimized, but are instead just pumped verbetim into your application. Learn to use a profiler instead. Most of the poor-performing code is due to bad algorithm choice and calling system functions that block execution. The slow code is easily found and corrected with careful study and a profiler.

Share this post

Link to post
Share on other sites
I'm not sure if it is still available, but in the past, Microsoft was giving away ml.exe (aka MASM) away for free. This is the Macro Assembly Compiler, it lets you write pure assembly. I know I got it with the Processor Pack for MSVC++ 6.0 and with the Windows Server 2003 DDK.

[Edited by - Mastaba on April 6, 2006 12:06:28 PM]

Share this post

Link to post
Share on other sites
Original post by ZedFx
didnt you mean

Nope. Not without knowing more about what he is doing and why.

Perhaps he wants his routine to be hot-swappable, such as taking advantage of a specific hardware provided function on an AMD-64, discovered by checking the CPUID. In that case he would have a general purpose function for use everywhere else (32-bit and 64-bit) in addition to the CPU specific function. He couldn't use a function pointer properly with that.

Perhaps he wants to handle debugging of exceptions (either CPU exceptions or C++ exceptions) or maybe he calls other functions in the application that throw these exceptions. Both of these need the prolog/epilog code to be present in order to function nicely.

Perhaps he wanted to instead have "int MyFunction()", and since naked functions cannot return values directly, he'd have to handle that.

Perhaps he would want to use a profiler on his code someday. These use prolog/epilog hooks. So he couldn't profile his naked function, meaning that he can't easily discover is his own version is actually faster than the version the compiler wrote.

If you are current on published compiler bugs you might note that naked functions have a disporportionately high number of code generation errors when turning on all the compiler optimizations -- which is an argument by itself to avoid them. Althought they are simple enough in concept, combining them with other compiler generated optimizations (which might also drop the prolog/epilog code, or might decide to inline it, or do other nice things) frequently end up breaking the optimizer's expectations.

No, I wouldn't recommend using a naked function without knowing a lot more about the specific situation.

And I certainly wouldn't recommend it in the For Beginners forum.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!