[TUHS] Memory management in Dennis Ritchie's C Compiler

Paul Ruizendaal pnr at planet.nl
Thu Aug 27 18:37:58 AEST 2020


Doug,

“In fact Dennis's compiler did not use AID instructions for that purpose.”

Whilst local variables are indeed accessed as an offset from the base pointer, I’m not sure that the above statement is correct. In the V6 compiler (-sp) was certainly used to push arguments to the stack, and when the register allocation overflowed, the interim results were pushed to the stack as well with (-sp).

See c10.c, the case CALL in rcexpr(), the function comarg() and sptab (which is right at the end of table.s)

Links:
https://www.tuhs.org/cgi-bin/utree.pl?file=V6/usr/source/c/c10.c
https://www.tuhs.org/cgi-bin/utree.pl?file=V6/usr/source/c/table.s

For interim result pushing/popping I refer to the FS and SS macro’s. Dennis discusses these in his “A tour of the C compiler” paper.
https://www.jslite.net/cgi-bin/9995/doc/tip/doc/old-ctour.pdf

Of course this is all implementational detail, not a core design aspect - as Richard Miller showed in his port to the Interdata architecture (including a port of the Ritchie C compiler). Maybe the sentence should have read: "In fact Dennis's compiler did not rely on having AID instructions for that purpose."

Paul

@Warren: at moments like these I really like having the line highlight feature that we discussed before Summer.





More information about the TUHS mailing list