I noticed alot of people on the www.cprogramming.com message board talking about using the _asm{} inline thing to replace some stuff that is compiled iniffeciently. I read that you can make functions in assembly and call them from C++. I've seen how to use asm for the main body of the function, and do everything.

addsomething(int X, int Y)
{assembly here}


I don't know much about assembly yet, but I'm wondering if I go about it like that, will I be losing many advantages of using assembly?
Can I call one of my C++ functions from within a block of assembly like that?

I've seen a tutorial mention that you can compile assembly as a library or something and use it for calling it's functions from C++

If you know where I can find resources that discuss this kind of stuff in detail I'd appreciate it.

Thanks in advance.
Posted on 2002-02-15 00:56:38 by WebSnozz

there are a couple of approaches to using assembler in VC++. You can either write it inline as you have mentioned which may effect some of the internal optimisation or you can write seperate modules and link them into your C++ program which is probably a better way to do it. For VC++ you will need to use MASM to get the correct module format. You will of course have to write your own prototypes in VC++ for the assembler modules you write.

To mix inline assembler and high level code, you will have to understand the conventions for register preservations used by VC++. With API calls its simple enough but with C++ functionality, you will have to read up the data with the VC++ compiler.


Posted on 2002-02-15 01:34:25 by hutch--
When you say I have to use MASM, is MASM32 an option if I go the route of linking?
Posted on 2002-02-15 01:42:12 by WebSnozz

MASM32 is built using ML.EXE which you need to assembler a module. You use the version of link that comes with the compiler for your VC++ code.

MASM32 has the information to build libraries out of modules and this is probably the most efficient way to handle assembler modules in VC++.


Posted on 2002-02-15 01:57:26 by hutch--
If you are doing any calculations inside a function, be sure to save all the final result to memory, don't expect EAX will be returned as the original value like we do in pure ASM. You can't create MASM stye macros(maybe if you use the linker that comes with masm32 it'll work). Remember that when you link inside VC++, the linker isn't MASM.

Happy Coding!!!
Posted on 2002-02-15 12:29:16 by stryker
I attached a VC project showing one approach. It's a simple program that finds the area of a circle, which isn't important, but it calls an assembly funciton to find it. In the workspace window right click on the areaproc.asm file and look at the custom build settings. You need to adjust the path to point to where ml.exe is installed on your system. If you have the processor pack for VC installed, you shouldn't need to specify the path.

Posted on 2002-02-15 15:18:58 by malone
I'll check that out, thanks all to all of you.:alright:
Posted on 2002-02-15 17:55:25 by WebSnozz