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 ?

Parents
  • 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.)

Reply
  • 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.)

Children
More questions in this forum