Static frames, Dynamic frames – Zilog Z8F0130 User Manual
Page 225

UM013037-1212
Call Frames
Zilog Developer Studio II – Z8 Encore!
User Manual
201
Static Frames
In the static frames scheme, for each function in the program, a single frame is statically
allocated at compile time for storing the call frame containing the parameters and local
variables of the function.
Static call frames can significantly increase code efficiency. However, this is a restrictive
call-frame scheme. This option must be used with some care because errors ensue if it is
applied blindly and your code uses either recursion or calls through function pointers. You
can avoid those errors by finding the functions that use those language features and declar-
ing them reentrant. In the case of function pointers, it is the functions to which the pointers
refer, not the functions that make the calls that must be marked as reentrant.
The advantage of static frames is that because the compiler knows the absolute address of
each function parameter, it can generate more compact code to access parameters than in
dynamic frames, where they must be accessed by offsetting from the stack pointer. For the
Z8 Encore! instruction set architecture, this code size savings is substantial. The savings
comes primarily not from using less space for frames, but from using less code to access
data in the frames. Thus, it is primarily a savings in code space, not in data space. It could
actually require more data space, although to mitigate this, the Z8 Encore! linker uses call-
graph techniques to overlay some function frames that cannot be simultaneously active.
The disadvantages of static frames are that they do not support two features of the C lan-
guage: recursion and making calls through function pointers. To allow a broader range of
applications to get the benefits of using static frames, the Z8 Encore! compiler provides
the
reentrant
keyword as another C language extension.
Dynamic Frames
The most familiar type of call frames, used exclusively by most desktop-oriented compil-
ers, are dynamic frames: when a function is called, space is dynamically allocated on the
stack to hold its return address, function parameters, and local variables.
Dynamic frames hold arguments and local variables on the run-time stack, allow recur-
sion, and allow reentrancy. Dynamic frames are the usual way of storing information
about an instance of a function call. Passing argument in dynamic frames is done by push-
ing the arguments on the stack in reverse (right to left) order.
Reentrant Keyword
This keyword notifies the compiler that in an application that otherwise uses static frames,
a dynamic frame must be used for any function declared reentrant.
For example, to declare the
recursive_fn
function as using a dynamic call frame, use
the following syntax:
reentrant int recursive_fn (int k)
{
if (k == 0)
- Z8F0131 Z8F0230 Z8F0231 Z8F0430 Z8F0431 Z8F043A Z8F0830 Z8F0831 Z8F083A Z8F1232 Z8F1233 Z8F0113 Z8F011A Z8F0123 Z8F012A Z8F0213 Z8F021A Z8F0223 Z8F022A Z8F0411 Z8F0412 Z8F0413 Z8F041A Z8F0421 Z8F0422 Z8F0423 Z8F042A Z8F0811 Z8F0812 Z8F0813 Z8F081A Z8F0821 Z8F0822 Z8F0823 Z8F082A Z8F0880 Z8F1621 Z8F1622 Z8F1680 Z8F1681 Z8F1682 Z8F2421 Z8F2422 Z8F2480 Z8F3221 Z8F3222 Z8F3281 Z8F3282 Z8F4821 Z8F4822 Z8F4823 Z8F6081 Z8F6082 Z8F6421 Z8F6422 Z8F6423 Z8F6481 Z8F6482 Z8FS021A ZMOT1AHH Z8FS040B ZMOT0BHH ZMOT0BSB Z8FMC04 Z8FMC08 Z8FMC16