I was reading the C language spec (C99) and I got to
wondring: are/were
there C implementations that had no stack, or a rising stack? There's a
falling stack in every implementation I've seen, but the spec doesn't
require it.
I've done C toolsets for many different architectures including the 8051
which has a hardware stack that rises.
In cases where there is no hardware stack defined on the processor, a C
implementation will typically simply define one - use a general purpose
addressing register (or even a memory location) as a stack pointer for
a "homemade stack" - The 8051 provides a good example of this as well,
the hardware stack addresses only the 128 bytes of internal RAM, not all
of which is usually available for a general purpose stack, so larger "memory
models" usually define another stack in external memory. The ARM is
another example, most software assumes R13 as a stack pointer, however
this is simply a matter of convention and is not tied to hardware capabilities
of that register. A stack (hardware or software) is the simplest way to
provide "auto" memory so most C implementations will provide one on one
form or another.
Among embedded toolsets for tiny processor, often without the means to
address the stack efficiently (the 8051 is a prime example of this as well),
you will often find a feature called "compiled stack" - the compiler builds
a call-tree (at compile time), and statically allocates memory for the locals
and other "auto" storage. Depending on the CPU, this can allow the
generation of MUCH more efficient code, and retains the benefit that
"auto" memory can be reused by different functions which are not active
at the same time (ie: the total amount of memory allocated is less than the
total sizes of all local variables etc. - if you simply declared "statics",
more
memory would be required). Obviously there are limitations, the most
obvious one being no recursive loops...
Regards,
Dave
--
dave06a (at) Dave Dunfield
dunfield (dot) Firmware development services & tools:
www.dunfield.com
com Collector of vintage computing equipment:
http://www.classiccmp.org/dunfield/index.html