How to pass parameter to a function from Assembly to C
I am using HCS08 and Code Warrio开发者_运维技巧r. I am calling a C function from assembly. How can I pass parameter to this C function?
What you want is the ABI, or Application Binary Interface for your platform. That will explain things like how to pass arguments to functions (registers, stack, a mix), which registers are caller saves and which are callee saves, special purposes for certain registers, and so on. By following a common ABI you are able to link libraries built by different compilers, mix high-level languages and so on.
For "big" platforms it's usually easy to find a document specifying the ABI. For others you may have to rely on disassembling a C function and looking at what it does. Pay attention to which registers it saves in its prologue and which ones it might smash. Also note how the prologue saves the stack pointer (or frame pointer) on entry because you will have to mimic that if you want debuggers to work.
It looks like the calling convention for HCS08 is documented by Freescale in an appnote.
Write c version (may be just a stub only passing arguments) for your function and analyse the code. Do your function same way. Calling method for specific function (in most cases) is uniquely defined by its set of arguments.
The common way is that first some arguments if they are integers or pointers passed in registers and the others are pushed on stack. But also note that varargs are often passed in different way than non-varargs.
Specially for 6808 which have few registers all parameters are likely passed through stack.
Well, i found the solution.
In assembly file declare the variable as:
XREF varaible1
and use it as memory location
In C file declare the variable as global.
extern char variable1;
精彩评论