Tuesday, July 28, 2009

How can I use a c function in
assembly code?

my code includes these parts:


extern _BFS


...


call _BFS


all arguments are pushed. also BFS.cpp exists in the directory, but I get this error:


undefined reference to `_BFS'

How can I use a c function in


assembly code?
C++ functions have their names mangled depending upon the number and type of arguments and the return value. 'C' functions have the same mangling. If use use __stdcall in front of your function, then it has has the name xxx@n where xxx is the name of the function and n is either the size of the arguments (usually 4 per argument) or just the count or the arguments. I forget which.





If you are trying access class member functions, then you have your work cut out for you. --- much harder
Reply:You need a C++ compiler to generate the object file, an assembler to translate your assembly to an object file and a linker to merge the two.





If you are successfully writing assembly language programs, you should have the assembler and linker. All you need is the c++ compiler.
Reply:Write it as a program and call it.
Reply:In addition you need to be careful when mixing c++ with assembly. The names of functions in c++ may not always translate into the exact same symbol in c/assembly. To be sure that they do wrap the function you want to call in





extern "C" {





}





If you are writing this on a POSIX environment (i.e. UNIX/Linux) then you can use objdump to see what symbols are part of the .o files you are linking against.


No comments:

Post a Comment