The & (address) operator and register allocation

Eric Green elg at killer.DALLAS.TX.US
Sat Dec 3 10:51:12 AEST 1988


in article <1224 at cps3xx.UUCP>, rang at cpsin3.cps.msu.edu (Anton Rang) says:
> have call-by-reference, is it possible to allocate variables which are
> passed by reference into registers?
>   For example, the C code:
> 
> 	scanf("%d", &N);
> 
>   would require that the address of N be taken to read it from the
> standard input.  If I then have a loop:
> 
> 	for (i=0; i<N; i++) { ... }
> 
> would the final program have to read N from memory each time?  

There was a discussion in comp.lang.c about this. There's two ways of
doing this: memory-mapped register set, or "smart" compiler that tries
to optimize register usage, e.g. keeping values in registers as long
as possible, and only dumping them to RAM when necessary for things
like the scanf call above. 
     AMD29000, SPARC, etc. don't have memory-mapped registers, and
thus use at least a semi-intelligent compiler. The Pyramid 90x has
memory-mapped registers. I suspect it's because Pyramid's early "C"
compiler was a bit, err, dumb (their "new" compiler, though, is quite
spiffy, global optimizer and all... I tried hand-tweaking the
assembly-language output once, and for the most part failed to make a
bit of difference).

> | Anton Rang (grad student) | "VMS Forever!"         | "Do worry...be SAD!" |
                                 ^^^^^^^^^^^
                                Gag choke BARF (;-)
--
Eric Lee Green    ..!{ames,decwrl,mit-eddie,osu-cis}!killer!elg
          Snail Mail P.O. Box 92191 Lafayette, LA 70509              
"We have treatments for disturbed persons, Nicholas. But, at least for
the moment, we have no treatment for disturbing persons." -- Dr. Island



More information about the Comp.lang.c mailing list