home .. forth .. misc mail list archive ..

Re: Variable number of arguments in registers


   Date: Wed, 20 Mar 1996 12:59:07 +0100
   From: Jaap van Ganswijk <ganswijk@xs4all.nl>

   I'm still wondering how current RISC processors that
   have only a limited number of registers in which they try
   to convey the function arguments, do this when there
   is an unknown number of arguments, like in printf().

   Is there any acceptable solution to this problem?

   Groeten,
   Jaap

TI's C compiler for the TMS320C40 has an option to compile function calls with
(a limited number of) arguments passed through registers.  The arguments in
excess, as well as "varargs" (as in printf) are still passed through a stack in
memory which is anyway needed to save registers and to build stack-frames for
local variables which are in excess with the number of registers which may be
used for caching local variables.
Argument passing through registers on the TMS320C40 saves memory accesses to
read the arguments, but when a function calls another one, it must first save
(push on the stack) the registers that it uses.  Therefore, argument passing
through registers is not always better than argument passing through the stack,
but it is efficient for shallow function-call trees.

On the SPARC, which has a slidding window of register sets for function calls,
an interrupt is generated when the slidding window "overflows" to allow the
saving(push)/restoring(pop) of the deepest register set, but the number of
registers in a set is still limited to 8 for argument passing (plus 8 for local
variables).  I have not looked in detail how they handle the case of functions
with more than 8 arguments (or more than 8 local variables), but I think that
they use an auxiliary stack in memory (pointed to by one of the 7 "global"
registers available) and generate code to push/pop it in such a case.

Hope that helps,
Christophe
--
email: Christophe.Lavarenne@inria.fr		tel: +33(1)39.63.55.80
INRIA, Domaine de Voluceau Rocquencourt		Institut National de Recherche
B.P.105 - 78153 LE CHESNAY CEDEX FRANCE		en Informatique et Automatique

SynDEx, CAD tool for the distributed implementation of real-time applications.
Take a look at our Web Server: http://www-rocq.inria.fr/syndex