Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!ucbvax!ucdavis!uop!greg From: greg@uop.EDU (Greg Onufer) Newsgroups: comp.lang.c Subject: Short code to determine compiler's register use Message-ID: <396@uop.uop.EDU> Date: 13 Jul 89 01:03:17 GMT Organization: University of the Pacific, Stockton, CA Lines: 49 Some students here had to determine the number of registers (data and address, we use 680x0's) the C compiler uses. A friend and I wrote the following code to show to some students having trouble. It is very short and simple, but it seems to work. The only logical next step is to post it to comp.lang.c and have it torn apart! We are interested in hearing about the results of this program when run on different architectures of machines and when compiled by different compilers, with and without optimization. The GNU C compiler should not be used, it will always return 19 (the max number of registers the program was written to find...), optimization on or off. Please reply to: Cheers!greg (cheers!greg@Apple.COM, cheers!greg@lll-winken.llnl.gov) ------------------------------------------------------------------- /* * Code to determine the number of registers a C compiler can use. * Compile WITHOUT optimization!! * G. Onufer / D. Christensen 5/12/89, early morning. */ #include main() { { int count1; /* Base of stackframe */ register x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19; { int count2; printf("Number of data registers = %d\n", 19 - abs(&count1 - &count2) + 1); } } { int count1; register *x1, *x2, *x3, *x4, *x5, *x6, *x7, *x8, *x9, *x10, *x11, *x12, *x13, *x14, *x15; register *x16, *x17, *x18, *x19; { int count2; /* Base of new stackframe */ printf("Number of address registers = %d\n", 19 - abs(&count1 - &count2) + 1); } } } ======================================================================