Hi all, I want to call a C function (for example: func1() ) from my old assembly code. The problem is that if func1() calls another C function( func2() ), what will happen? How does the compiler pass parameters to the second function? If it also passes through R1-R7, does it destroy the parameters of func1()? Thanks for reading this topic.
"The problem is that if func1() calls another C function( func2() )" That is entirely irrelevant! The C51 calling convention defines how to call a function. It is the same for every function - that's the whole point of a calling convention. "If it also passes through R1-R7, does it destroy the parameters of func1()?" It will ensure that it does not destroy anything that it'll need again! Note that your assembler code must assume that the C51 function call will destroy all registers. You have read the chapter in the Manual on interfacing C51 and Assembler, haven't you?!
To Andy Neil, I have read the manual, of course. But in the manual's example, it only calls one C function, and it doesn't save any registers!!! So I confuse that if the first C function calls another C function in it, does it save the registers? I also see that, in the Large Model Example, page 171, line 11:
MOV R0, #?_funtion?BYTE+3
MOV DPTR, #_?function?BYTE+3
"I confuse that if the first C function calls another C function" What happens inside the function is entirely irrelevant - See my original post. You just need to see the function as a "black box" - it has a defined interface, and what actually goes on inside the box is of no concern.
View all questions in Keil forum