Automatic (local) variables and parameters to functions are placed
on the stack for most targets. For MCS51/DS390/HC08/S08/MOS6502/PDK13/PDK14/PDK15
they can either be placed on the stack or in data-space. The default
action of the compiler is to place these variables in the internal
RAM (for small model) or external RAM (for medium or large model).
This in fact makes them similar to static so
by default functions are non-reentrant.
They can be placed on the stack by using the —stack-auto
option, by using #pragma stackauto
or by using the __reentrant keyword in
the function declaration, e.g.:
unsigned char foo(char i) __reentrantSince stack space on 8051 and MOS6502 is limited, and accessing the stack is slow for the Padauk, the __reentrant keyword or the —stack-auto option should be used sparingly. Note that the __reentrant keyword just means that the parameters & local variables will be allocated to the stack, it does not mean that the function is register bank independent.
{
...
}
unsigned char foo(__xdata int parm)In the above example the parameter parm and the variable i will be allocated in the external ram, bvar in bit addressable space and j in internal ram. When compiled with —stack-auto or when a function is declared as reentrant this should only be done for static variables.
{
__xdata unsigned char i;
__bit bvar;
__data unsigned char __at (0x31) j;
...
}
It is however allowed to use bit parameters in reentrant functions and also non-static local bit variables are supported. Efficient use is limited to 8 semi-bitregisters in bit space. They are pushed and popped to stack as a single byte just like the normal registers.