Archived

This topic is now archived and is closed to further replies.

Dream Lord

Newbie - C and Asembly interface

Recommended Posts

Hi, Allow me to introduce myself: I''m a computer engineering undergraduate student at UNICAMP, Brasil. Although I have knowledge about C and assembly languages, I don''t know much about how they interact. I know I can simply type "asm" at the beginning of a line and write an assembly instruction, but can I call a sobroutine that i wrote entirely in assembly in another file? Is there any other way, rather then the "asm" at the beginning of the line, for me to use assembly code in a C program? Thanks in advance, Morpheus "Sleep is the prime of death" --Coelho Neto

Share this post


Link to post
Share on other sites
depends what compiler you''re using. most compilers you can actually just type in the code. with all compilers you can link an object file that was created with an assembler like NASM.


Never underestimante the power of stupid people in large groups.

Share this post


Link to post
Share on other sites
Of course, you have to set up the assembly source file correctly to let it know that it''s procedures will be used in a C file. If you are using a C++ compiler, you have have to declare all the external assembly procedures as extern "C" so the compiler doesn''t mangle the names and confust itself.

Share this post


Link to post
Share on other sites
In lots of compilers now you can use c variables in assembly, so that''s easier. Arguments are pushed onto the stack in right to left order unless you specify not to. I believe that you mov something into eax to return a value, but I''m not sure about that. Sure, you can use pure asm functions, you''ve just got to compile your .c and .asm(or .s) files into object files instead of a complete program, then link them yourself. It''s easier to do this when using a unix(or linux) based os, but it''s entirely possible in windows. Also when specifing functions in asm I think there''s a naming convention like

void ThisFunc()

func ThisFuncA

I haven''t used asm functions in a while so I''m not sure, look it up.

Share this post


Link to post
Share on other sites
That''s exactly what i was looking for: link objects compiled in c and in assembly.
How do I tell the C (not C++) program that a function is in the .asm file (so that it won''t crack at compilation)? And how do I make that assembly routine public? Just like when using only assembler (that is, "public ")?

If i''m not asking to much, i could really use an example...


Again, Thanks!!!




Morpheus

"Sleep is the prime of death"
--Coelho Neto

Share this post


Link to post
Share on other sites