This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reentrant Function call

Hi.
I m using 89C51. I have made all those functions that are called from non-ISR as well as ISR as reentrant and defined reentrant stack in XDATA. Here, i want to know that for each call to reentrant function, process will do the PUSH and POP operation to store local variables and function's arguments on simulated reentrant stack or only in those cases when interrupt occurs during the execution of reentrnat function ?

  • Every call. The generated code for a reentrant function will do its business on the software stack, regardless of how it is invoked.

    (If the function only needed the stack during an interrupt, then non-interrupt invocations would be using some other memory, the stack invocations would have the stack all to themselves, and thus you wouldn't actually need the stack at all, but could statically allocate memory at compile time -- unless the function was recusive as well, which seems unwise for a function in an interrupt handler.

    The reason to have a stack is to manage memory allocation for parameters, locals, etc, at run time. It costs more time, code, and data space to do this work dynamically, so you'd prefer to do so at compile time if possible. However, a compiler doesn't always have good information about the call tree at compile time. Limitations to the knowledge of the compile-time analysis include calls from multiple contexts (interrupt handlers or preemptive tasks) as well as many uses of function pointers. These cases are the ones that perhaps call for the use of reentrant.)

  • Hi Drew..
    Thanks for the reply. I need one more suggestion from ur side. I was facing a problem regarding recursion. For some functions that must be recursive for my code. While i m builing the code, linker gives error for recursive call. So to avoid this, i made all those functions reentrant, even though those functions are not called from any ISR at all. So by declaring them as reentrant, i am able to avoid the linker warnings. But my concern is that during each call to these function, processor will perform PUSH & POP operation which will slow down the performance. So can you suggest the way to achieve this. Instead of making those functions reentrant, if i use linker overlay option and seperate out those functions from default overlay analysis then also linker will not generate recursive call warnings. e.g. func1 ! *, func2 ! *,...

    Will it be good to use overlay option instead of making all functions reentrant ??

    waiting for ur critical input...

    Bye

    Thanks.

  • I was facing a problem regarding recursion. For some functions that must be recursive for my code. While i m builing the code, linker gives error for recursive call. So to avoid this, i made all those functions reentrant, even though those functions are not called from any ISR at all.
    HOW can a function be recursive without being reentrant??????

    But my concern is that during each call to these function, processor will perform PUSH & POP operation which will slow down the performance.
    You can not have your cake and eat it too. Either you design your program before you code it or you just code away happily and end up in the mess you are in.

    So can you suggest the way to achieve this. Instead of making those functions reentrant
    Sure 1) NO recursive functions 2) NO reentrant functions

    Will it be good to use overlay option instead of making all functions reentrant ??
    The overlay that get active at optimization 2 and up can NOT be used (for physical reasons - not the compilers fault) for functions that are reentrant or recursive.

    If you had not been concerned with speed, there MAY have been ways to save your code, but sicnce you are only one way exist: Throw away you code, design the project to be non-reentrant and non-recursive and start over. Sorry, but I see no other way.

    Erik

  • Hi erik,
    Thanks for the suggestion. This will help me a lot.