Thread: C to assembly interface

  1. #1
    Registered User
    Join Date
    Feb 2003

    C to assembly interface

    I have bunch of C and assembly files. C module makes call to routine in assembly and vice versa. But assembly language platform can change from one processor to another but we would like to keep C module unchanged.

    This is design issue and system is real time so we need very memory efficient and less code consuming technique.

    Option which I think of
    1. Declare as global structure, first parameters will be pointer to function, second byte is length of parameters and type of parameters. Third, fourth and fifth words may contain byte, word or pointer.

    Before calling the assembly function, fill the structure with this data and call the common gate routine. The common gate routine will fill the register specific to processor and invoke the assembly routine. Once assembly routine returns, fill the respective retrn value in register specic to processor and return back to C routine.

    I wanted to know your inputs.


    l interface routine and restrict the number of parameters to

  2. #2
    Registered User
    Join Date
    Sep 2004
    Is it possible to rewrite the asm routines in C? If so, then that's definitely your best solution. If not, then something similar to what you outlined should work.

    A better solution might be to place the asm routines in C functions with inline asm. This makes it easy to pass the data back and forth between the C and asm functions. The method of doing this varies from compiler to compiler, but it probably looks something like:
    void my_function()
        _asm {
            // your asm routine goes here
        // Put C code here to handle the result of the asm routine
    Look up how to write inline assembly in your compiler's documentation.

  3. #3
    Registered User
    Join Date
    Feb 2003
    The assembly routine may be called from another assembly module too. Will that be possible?

    I am not getting how to implement the function pointer part of the solution that I discussed. Can anybody help in that.

    Like If I want to call routine abc from C module

    Then, I need to equate function pointer( first parmater) to actual function pointer which coule be near pointer or far pointer. Can you please shed liht on how do I do that?


  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Does your toolchain document the assembly interface and/or calling convention? Most do.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Feb 2003
    Since it is time critical, we are planning to restict number of parameters to max 3 and pass parameters thro' registers. If we use stack then we have to change the assembly code which already exists.

    Basically we are rearing apart the all assembly modules and converting part of them to C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  2. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 01:11 PM
  3. OOP in C
    By lyx in forum C Programming
    Replies: 4
    Last Post: 11-23-2003, 01:12 PM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 03:35 AM