Using 'c++' in 'assembly' - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Using 'c++' in 'assembly'

saeidmscssaeidmscs Posts: 5Member
Hi every one
Is it possible to use functions and file coded by c++ in assembly?
for example,we have written a function in a 'cpp file',can we use this function in 'asm file'?
If we can,how?


  • anthrax11anthrax11 Posts: 511Member
    You can compile the c++ file and assemble the asm file into object files and then statically link them together into one executable. Or you can make a dynamically linked library of the c++ file and call it from the asm program. If they are small functions, then the first option makes more sense.
  • 3y3ty3y3ty Posts: 15Member
    Give me convenience, or give me death...

    I'm not sure if C++ uses the same calling convention as
    C, but if your going to call modules written for a high-level
    language you have to obey the language's calling convention.
    Same rule applies if your assembly module is being
    called by a high-level language.
    For the C calling convention the functions arguments
    are pushed in reverse order onto the stack.
    int func(int a,int b) --->

    |###b###| sp+2
    |###a###| sp

    End of message.
    muFx |____________________________
  • kazdaxkazdax Posts: 16Member
    why does someone not show its actually done..isntead of making stories about this and that..perhaps other people might need a tutorial on this ? cant you take 15 mintuea of your time to hel pthe guy ? like actually help ..not retardation
  • anthrax11anthrax11 Posts: 511Member
    There was no mention of what the purpose was or what assembler or compiler is used, so it doesn't make sense to give out links to random tutorials if we don't know half the details. Some assembly languages have built-in syntax for setting the calling convention, some don't. Some compilers need specially named functions in the object files, some don't. Some development environments have specific ways to set the link dependencies in an IDE, others use the command line. If DLLs are used, then an entirely different approach would be needed.

    Linking c++ to assembly is a relatively advanced thing to do, you can't expect easy solutions where one size fits all. A general question was asked, a general answer was given. If you need more information, then we'll be happy to give it. Just ask, give more details and we'll guide a person to the right path. That's how a forum works.

    I hope this was a good enough explanation.
  • neocambellneocambell Posts: 6Member
    Have a look at [link=]Calling C/C++ function from ASM code[/link]
Sign In or Register to comment.