Continue to Site

Welcome to EDAboard.com

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.

HELP: C and assembly interfacing

Status
Not open for further replies.

fanghl

Newbie level 4
Joined
Jul 8, 2006
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Seattle
Activity points
1,319
hi,

I'm trying to call a C function from an asm file. Can someone help me with the right syntax and procedures? Thanks a lot.
 

I don't think it is possible ..
Calling ASM from C - by all means - but not the opposite way around ..

Regards,
IanP
 

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.
 

Seems you should be able to do it somehow..


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.

Alan
 

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.
 

use #pragma preprcessor directive and call asm code from a c program
 

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 .
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top