As I can see, the keil compiler doesnt use regular stack for functions, and all the local variables inside functions are mapped in global memory. Is there a way, to make it behaive like a normal program should? I.E - create a local variables in ram,and destroy them, when the function ends? Thank you.
Is there a way, to make it behaive like a normal program should? Define "normal". Do you mean "like processors for desktop computers do it" ? That's not "normal". And the '51 is not a processor for a desktop computer, it's a microcontroller. Anyway. Andy said everything that should be said about this topic. Apart from reentrancy, there is pretty much no need for resorting to a slow, inefficient variables-on-stack approach.
"slow, inefficient variables-on-stack approach." Hmm... interesting. Indirect addressing will always be slower & use more code than direct addressing - on any processor. So a better question might be, "how can I get the speed & efficiency of C51's approach in other compilers?"! The thing is, using the stack makes life easier for the compiler; the C51 approach means, as previously noted, that the tools have to do all the hard work at build time - but the result is faster, tighter code! C51 has to do it this way, because of the architectural limitations of the 8051; other compilers just choose to take the easy way out - because they can!
Woa, so much nervious replies. Get easy on the coffee,ok? I will try to make myself clear this time. -- When the function is called,it should create variables to use. It should use some pool ,and release it,after it is done (unless it's static variable,but i'm not talking about it). Now, if i'm having some parsing functions, i have to use one common pool, cant define array or other variables in function (nvm that one). "reentrant" key does make the function to do what i intend, but the assembly is so ugly, and it immediately involves so much bugs with optimization, that i have to disable it (optim.) About "slow-inneficient-stack-approach" Excuse me, but I have only 8k Ram,and i care less about couple of ms. So i prefer the function to do some pushing,popping,calling. The general question was - how do i make it? (Wihtout reentrant) PS. Erik - [yes, there is and, amazingly enough, that is how it works. That the stack is not involved does not disable thais.] Local variables are defined in stack. No stack - no local variables.
"Excuse me, but I have only 8k Ram,and i care less about couple of ms." no you have only 248 bytes at max for stack Stack is always in IRAM on x51. So putting local vars on stack might be a bad idea. Thomas
Okay. So the only way is to define myself a pool of memory in global area , and use it from functions. Thank you.
View all questions in Keil forum