I am new to C language programming of LPC935 MICROCONTROLLER. actually i want to call a function( which is written in assembly language) from C language program. please tell me how to do it. or if there is any option to write some code in assembly in continuation with C . please help in this regard also
to combine C language program and ASSEMBLY language program
Oct 05, 2006
10 Replies
The only place to find the answer to this is the documentation of your C compiler, since this is implementation dependent.
Meindert
The chances of me guessing which compiler you are using a pretty slim. Have you read the compiler documentation?
Regards, Richard.
- formatting link
- formatting linkfor Cortex-M3, ARM7, ARM9, HCS12, H8S, MSP430 Microblaze, Coldfire, AVR, x86, 8051, PIC24 & PIC18
An educated guess is - Your probably using the Keil Complier.
Yes, you can pass arguments in a C function to ASM.
Answer here
formatting link
All about the Keil C51 complier here.
formatting link
You need to read up in your compiler manual on things like (at a bare minimum) how it passes arguments, which registers you're allowed to trash and which ones you need to preserve, and how it expects results to be returned.
As to inline assembly (if that's what your question refers to), you need to read up on that too in your compiler manual.
Hi, thanks for reply. i m using Keil Compiler. can u suggest me the way if possible, to write a 7 line assembly code in the middle of C language program. also i want to use one parameter from C language program.
Hi, thanks for reply. Yes, i m using Keil Compiler. can u suggest me the way if possible, to write a 7 line assembly code in the middle of C language program. also i want to use one parameter from C language program.
The easiest way I know is to write the asm program in a separate file and just add this to your project. This way, you're not writing inline asm code but rather a c-callable function in assembler. A single parameter is passed from C to your function in r6:r7 (int) or r7 (char). You have to start your function's name with an underscore in the asm file:
.public _myfunc
_myfunc: inc r7 ret
In the c file, you declare your function as extern e.g.
extern char myfunc (char);
please tell me how do i take a return value( if it is a char) from assembly program. i call a assembly function like this unsigned char sum = funtion( j ) ; in what register i have to store my value which i want to return.
Again, that is in the documentation of your compiler!!!
Meindert
r7
Assuming you're using C51
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required