Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
To call a C function from assembly requires at the very least, setting up the stack as if a C function made the call. Depending on the complexity of the called function you may need to set up a stack frame, allocate and initialize variables local and global, perhaps even initialize and call libraries.
But for a simple C function I would write a small C test program to call the function and compile it to generate an assembly listing (or just dissassemble the resulting code) and see what C does to call the function.
Have the main C program simply call your assembly program as a function. The Assembly prog really does all the work, and when it needs the C function it returns back to C, with the needed arguments for the C function returned. Your C program shell then calls the C function with those arguments, then returns to the assembly prog by calling it again with the C function results as an argument.
You just have to make your assembly program start up with bad or known arguments for starting, then subsequent reentries are actually function value returns.
hi. i'm newbie in uc. just want to asked if c and assembly can be compiled as a single prgram. say, pid in c and motor control and lcd display in asm. if so, how to do this and if not, what's the best way to solve? any help will do. thanks, more power to EDA board.
The easiest way to call an asm function from C or to call a C function from asm is to use the Library manager of your toolset. Compile the code to a library function and link in the library!
to call c function from assembly you need to know C calling convention and actual synthax of of your assembler. Usually it is implementation specific - it is up to particular compiler how to make call to function and where to put function arguments. You have to consult your compiler manual for C calling conventions . For sure it is there just have a look.
Let say for IAR AVR compiler there is manual called "Compiler reference" with clause "Assembler language interface"
For intel and mips i so stadards called application binary interface (ABI) - it was attempt to put some standard among compiler vendors to have same calling conventions .
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.