I have a function _writeHexASCII in assembly language that needs to be called
its takes two parameters (*int, unsigned long int)
How do I declare it in C so I can use it?
Printable View
I have a function _writeHexASCII in assembly language that needs to be called
its takes two parameters (*int, unsigned long int)
How do I declare it in C so I can use it?
Take heed to note what the function returns and who cleans the stack (the function or the caller?).Code:extern return_type calling_convention writeHexASCII(int* p, unsigned long int n);
It may be tricky.
Then again, the assembly needs to be declared so the linker can find it. I can't help on that point.
Link it.Code:extern void writeHexASCII(int *, unsigned long int);
Don't forget calling convention and return type (or does C have calling convention?).
All languages have a calling convention. The question is, of course, if the assembler being called is following the standard C calling convention in that particular machine. If not, the next question is to figure out if the calling convention expected by the assembler can be achieved from the particular compiler.
The calling convention determines:
1. Who cleans up the stack - caller or callee.
2. How parameters are passed, in registers (if so, how many registers and in which order) or on the stack. Also in which order the arguments are passed on the stack.
3. Which registers the function can use directly, and which registers must be preserved by the callee.
4. How the return value is returned to the caller, if there is a return value.
--
Mats