1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

to combine C language program and ASSEMBLY language program

Discussion in 'Embedded' started by manoj, Oct 5, 2006.

  1. manoj

    manoj Guest

    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
     
    manoj, Oct 5, 2006
    #1
    1. Advertisements

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

    Meindert
     
    Meindert Sprang, Oct 5, 2006
    #2
    1. Advertisements

  3. manoj

    FreeRTOS.org Guest

    I am new to C language programming of LPC935 MICROCONTROLLER. actually
    The chances of me guessing which compiler you are using a pretty slim. Have
    you read the compiler documentation?

    Regards,
    Richard.

    + http://www.FreeRTOS.org
    + http://www.SafeRTOS.com
    for Cortex-M3, ARM7, ARM9, HCS12, H8S, MSP430
    Microblaze, Coldfire, AVR, x86, 8051, PIC24 & PIC18
     
    FreeRTOS.org, Oct 5, 2006
    #3
  4. Joe G \(Home\), Oct 5, 2006
    #4
  5. manoj

    Mike Silva Guest

    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.
     
    Mike Silva, Oct 5, 2006
    #5
  6. manoj

    manoj Guest

    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.
     
    manoj, Oct 5, 2006
    #6
  7. manoj

    manoj Guest

    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.
     
    manoj, Oct 5, 2006
    #7
  8. manoj

    Viktor Guest

    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);
     
    Viktor, Oct 5, 2006
    #8
  9. manoj

    manoj Guest

    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.
     
    manoj, Oct 6, 2006
    #9
  10. Again, that is in the documentation of your compiler!!!

    Meindert
     
    Meindert Sprang, Oct 6, 2006
    #10
  11. manoj

    Viktor Guest

    r7

    Assuming you're using C51
     
    Viktor, Oct 6, 2006
    #11
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.