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
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:
Look up how to write inline assembly in your compiler's documentation.
// your asm routine goes here
// Put C code here to handle the result of the asm routine
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?
Does your toolchain document the assembly interface and/or calling convention? Most do.
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.