Optimization of Assembly Language Code
Optimization of Assembly Language Code
Goals: This laboratory investigates the assembly code generated by
the pc and gcc compilers. The lab asks you to compare the
code generated when the compiler tries to optimize code.
Resource: As with the previous lab, you will want to refer to HP's
manual,
PA-RISC 1.1 Architecture and Instruction Set Reference Manual,
Third Edition.
Preparation: Before the laboratory session, read the Pascal and C
programs FahrToCelsius which are found as files table.p and
table.c in directory ~walker/assembly.
Steps for this Lab:
-
Focusing on either the Pascal or the C program, compile the program to
assembly to determine what code is produced using either the pc or
gcc compiler.
-
Both of these compilers will attempt some optimization of the
code if you use the -O option. E.g., type:
pc -S -O table.p
or
gcc -S -O table.c
-
Compare the non-optimized and optimized code generated by the
compiler you selected. For example, you should observe the nature of any
changes between the two assembly language listings. Are registers used
differently? Are some instructions omitted? Are different types of
instructions used? Is one listing significantly shorter?
Also, in addition to the above discussion, for both your
non-optimized and optimized code:
-
draw a picture of the registers and show which registers are used for what
purposes,
-
draw a picture of the run-time stack to show what values
are stored where (relative to %r30 and/or %r3), and
-
discuss how the floating point arithmetic is handled.
Notes:
-
Your work for this lab may be limited to the output from just one of the
compilers mentioned. During class, we may have the chance to hear about
each compiler.
-
In answering the above questions, you need not annotate the assembly
language programs. In making comparisons or in discussing approaches, you
may find it helpful to comment upon specific instructions or code segments,
but there is no need to annotate the entire assembly language code.
Work to be turned in:
-
Step 3 for either Pascal or C (but not both).
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/211/labs/lab.code-optimization.html
created October 1, 1997
last revised October 1, 1997