Java Reference
In-Depth Information
7. Most C compilers (including the GCC compilers) allow a user to ex-
amine the machine instructions generated for a given source program.
Run the following program through such a C compiler and examine the
instructions generated for the for loop. Next, recompile the program,
enabling optimization, and reexamine the instructions generated for the
for loop. What improvements have been made? Assuming that the
program spends all of its time in the for loop, estimate the speedup
obtained. Write a suitable main C function that allocates and initializes
a million-element array to pass to proc. Execute and time the unopti-
mized and optimized versions of the program and evaluate the accuracy
of your estimate.
int proc(int a[]) {
int sum = 0, i;
for (i=0; i < 1000000; i++)
sum += a[i];
return sum;
}
8. C is sometimes called the universal assembly language in light of its
ability to be very e
ciently implemented on a wide variety of computer
architectures. In light of this characterization, some compiler writers
have chosen to generate C code as their output instead of a particular
machine language. What are the advantages to this approach to compi-
lation? Are there any disadvantages?
9. Many computer systems provide an interactive debugger (for example,
gdb or dbx) to assist users in diagnosing and correcting runtime errors.
Although a debugger is run long after a compiler has done its job, the
two tools still must cooperate. What information (beyond the transla-
tion of a program) must a compiler supply to support e
ff
ective runtime
debugging?
10. Assume you have a source program P . It is possible to transform P
into an equivalent program P by reformatting P (by adding or deleting
spaces, tabs, and line breaks), systematically renaming its variables (for
example, changing all occurrences of sum to total), and reordering the
definition of variables and subroutines.
Although P and P are equivalent, they may well look very di
erent.
How could a compiler be modified to compare two programs and de-
termine if they are equivalent (or very similar)? In what circumstances
would such a tool be useful?
ff
 
Search WWH ::




Custom Search