Skip to main content
GameDev.net gamedev.net
🔒 Locked

Assembly and C

Started by robertocarlos Feb 28, 2003 at 5:58 PM 3 replies 400+ views
Original Post
robertocarlos
robertocarlos
I want to integrate code written in assembly and code written in C. I''m not using inline assembly. I want to compile code seperately and then link them. Can someone help please? "Time flies like an arrow, Fruit flies like a banana."
The sky is the limit !
Extrarius
Extrarius
The method you use depends on the compiler, assembler, and linker that you are using, but one thing you''ll most likely have to do in any case is prefix all your functions defined in assembler with a leading underscore, so instead of calling the function dowhatever you would have to call it _dowhatever in the assembly files (because C prefixes functions with a _ ).

----------
Almost typo-ified using Extrarius'' AUTOMATIC Typo Generator, but I decided to be nice =-)
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
robertocarlos
robertocarlos
Thanks. I''m using MASM and VC 6.
The sky is the limit !
Extrarius
Extrarius
Well, if I remeber correctly all you have to do in that case is just add your .asm file to the project normally and it will be assembled and linked in with the rest of the files to make the exe, assuming VS is configured properly (I don''t remeber having to do anything special to get assembly to work, but it''s been a long time since I''ve used asm, so I could have forgotten something)

----------
Almost typo-ified using Extrarius'' AUTOMATIC Typo Generator, but I decided to be nice =-)
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
LilBudyWizer
LilBudyWizer
I think you will also need to use extern "c" to prevent name mangling for C+. I believe in TASM there is a macro to generate mangled names so there might be a similar macro in MASM. Even so it will still be implementation dependant and extern "c" would be the correct way to go. As far as the receiving end, i.e. calling assembler routines, it is up to your assembler program to use the stack correctly. Easiest is just to look at what the compiler generates for calls to c/c++ routines and what happens once you are in them.
Keys to success: Ability, ambition and opportunity.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.