We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I was wondering why the Keil compiler doesn't allow an option for re-entrancy where some internal RAM is pushed on the stack upon function entry and popped off the stack upon exit. Doing it this way would allow access to the variables to be accessed with direct memory locations (more efficient) and yet the function is re-entrant. One slight problem is if pointers to an auto variable are passed to another re-entrant function, but if a pointer is used this way, don't access that variable with this method, use the inefficient stack method instead. I also think with the large memory model, any static variables in a function that don't have pointers could also be accessed this way; group them all together in external memory and on function entry, copy them into internal RAM and copy them out whenever a subroutine is called or the function exits. I'm sure the programmers at Keil have considered this and rejected it for some reason that I am wondering why?
I have serious doubt this can really end you up with a re-entrant function. Re-entrancy and any kind of direct memory access (i.e. via a hard-coded address, instead of indirectly via a pointer register) are strictly contradicting each other. This would only be different if you used indirect memory (IRAM) in this way. But since IRAM is scarce, this would limit the amount of possible re-entrancy rather strongly.