2

I wan to learn
1). How to call assembly code so that I can call it from C++?
2). I want to keep all my assembly code in separate files.

I am using Linux,GCC and other GNU developer tools.

Can you please provide some good references for it?

1 Answer 1

4

Write C++ header files declaring the functions you want. Define those functions with assembly language in another file. build object files of the assembly language code. Then in other C++ code files, #include the header which contains the declarations of your assembly code defined functions. Call the functions as any C++ functions, link against the object file as you link with any object file.

For references, read the code of some project that uses a mix of assembly language and C/C++. Device drivers could export functions that way.

Sign up to request clarification or add additional context in comments.

2 Comments

Sure without extern "C". You'd have to mangle the names yourself in the .s file, but you have to implement the entire rest of the callee side of the ABI anyway, so why not?
Ah, I see ... depends on what you need .. if C linkage is sufficient, then it'd probably be easier...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.