Article View: comp.arch
Article #12861Re: Available no. of registers
From: Chris Torek
Date: Thu, 22 Jan 1987 19:48
Date: Thu, 22 Jan 1987 19:48
49 lines
2415 bytes
2415 bytes
In article <1029@cuuxb.UUCP> mwm@cuuxb.UUCP (Marc W. Mengel) writes:
>Unfortunately, you don't have to take the address of a given variable
>to use it, you merely have to take the address of a variable near it
>and add an offset to it. The way C is defined, this is quite legal.
Legal indeed, but the result is undefined. Taking the address of
an adressable object is all right, and offsetting that is fine;
but no mention is made of where the resultant pointer points, if
anywhere.
>For example, suppose I have a function f, declared as follows:
> f(p) struct { int a, b, c; } *p; { ... }
>And I call it as follows:
> b() { int a, b, c; f( &a ); }
>According to our venerable friends kerningham&ritchie, this is legal;
How so?
>it is also used to some great extent in the older (v6 & v7) unix kernels.
The kernels have many instances of code such as
struct { /* ioctl arguments, e.g. */
int fd;
int cmd;
caddr_t addr;
} *uap;
The kernel, however, is one of those inherently machine specific
things; it is allowed to cheat. This cheating is (generally) very
carefully controlled so as not to cause trouble with the compiler.
There is nothing in C that requires that independently declared
variables be adjacent in terms of pointer arithmetic. Arrays must
be so, but on, e.g., a Pyramid, the thirteenth scalar stack variable
is nowhere near the first twelve:
f()
{
int a, b, c, d, e, f, g, h, i, j, k, l; /* registers */
int m, n, o; /* stack */
...
As the registers in the Pyramid are addressable, the compiler simply
puts the first twelve variables that fit into the twelve free local
registers. (There are twelve standard parameter registers as well.)
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP: seismo!mimsy!chris ARPA/CSNet: chris@mimsy.umd.edu
Technical Details
Message-ID:
<5151@mimsy.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mimsy!chrisReferences:
<3810002@nucsrl.UUCP> <926@mips.UUCP> <759@vaxb.calgary.UUCP> <1029@cuuxb.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.arch Subject: Re: Available no. of registers Message-ID: <5151@mimsy.UUCP> Date: Thu, 22-Jan-87 14:48:59 EST Article-I.D.: mimsy.5151 Posted: Thu Jan 22 14:48:59 1987 Date-Received: Thu, 22-Jan-87 21:45:53 EST References: <3810002@nucsrl.UUCP> <926@mips.UUCP> <759@vaxb.calgary.UUCP> <1029@cuuxb.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 49