to combine C language program and ASSEMBLY language program

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

Reply to
manoj
Loading thread data ...

The only place to find the answer to this is the documentation of your C compiler, since this is implementation dependent.

Meindert

Reply to
Meindert Sprang

The chances of me guessing which compiler you are using a pretty slim. Have you read the compiler documentation?

Regards, Richard.

  • formatting link
  • formatting link
    for Cortex-M3, ARM7, ARM9, HCS12, H8S, MSP430 Microblaze, Coldfire, AVR, x86, 8051, PIC24 & PIC18
Reply to
FreeRTOS.org

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

Reply to
Joe G (Home)

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.

Reply to
Mike Silva

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.

Reply to
manoj

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.

Reply to
manoj

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);

Reply to
Viktor

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.

Reply to
manoj

Again, that is in the documentation of your compiler!!!

Meindert

Reply to
Meindert Sprang

r7

Assuming you're using C51

Reply to
Viktor

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.