Xref: utzoo comp.arch:7426 comp.lang.c:14485
Newsgroups: comp.arch,comp.lang.c
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: The & (address) operator and register allocation
Message-ID: <1988Dec3.221843.28966@utzoo.uucp>
Organization: U of Toronto Zoology
References: <1224@cps3xx.UUCP>
Date: Sat, 3 Dec 88 22:18:43 GMT

In article <1224@cps3xx.UUCP> rang@cpswh.cps.msu.edu (Anton Rang) writes:
>... Since the C language doesn't
>have call-by-reference, is it possible to allocate variables which are
>passed by reference into registers?

Within limits.  Barring the possibility that the machine allows pointers
to registers, the requirement is that the register and memory copies track
changes to each other.  This is tricky but not entirely impossible, at
least in restricted cases with some arguably-dubious assumptions.

>...the above example--the address of N could have been saved in scanf()...

The compiler may know that it isn't, since scanf is a standard library
function.  It may even know it for your own functions, if it does fancy
interprocedural analysis.

>  Are there any architectures which allow taking the "address" of a
>register...

The original Berkeley RISC design had registers with addresses, carefully
set up in such a way that you could pass pointers to them around freely.
The idea was to maximize the ability to put local variables into registers.
I don't know of anybody commercial who's copied this idea.
-- 
SunOSish, adj:  requiring      |     Henry Spencer at U of Toronto Zoology
32-bit bug numbers.            | uunet!attcan!utzoo!henry henry@zoo.toronto.edu