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.

How to Use C code to call assembly's function

Status
Not open for further replies.

feiutm9898

Full Member level 4
Joined
May 31, 2004
Messages
224
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,296
Location
Singapore
Activity points
2,027
Can anyone help me the code below. I need to call assembly function by using C code. The #define macro is ok. But there is compilation error at main ().

-----------------------------------------------------
1) Let's say I have a assembly code below:
.GLOBAL AssemblyFun
AssemblyFun:
nop;
nop;
.
.

2) I define them as macro I define them

#define C_function(void) AssemblyFun(void)

3) I use C code to call the assembly function

main ()
{

C_function();

}
-------------------------------------------------------
 

I think this is highly dependent on your C compiler. Usually, when I need to interface C and assembly, I write the function prototype in C, then I compile the C source file, instructing the compiler to generate the (dis)assembly list.

Then, you have to open this list file to see how the compiler call the assembly function, and pass the parameters (for example, your routine in ASM may expect some variables tro be passed trough a register, or trought the stack). This step is only necessary for you to understand how your ASM routine will receive its parameters.

After understandig how the C compiler will interface with the ASM routine, you show instruct the pre-processaor via a compiler directive (__ASM__ for example, but you should look in your compiler manual), that the code following the directive will be in assembly, so the processor doesn't generante a syntax error.
 

    feiutm9898

    Points: 2
    Helpful Answer Positive Rating
You dont need the macro, just call
'AssemblyFun();'
If the codes are in seperate files, you need to use a 'h' file for the linker.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top