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. This is available on-line in either html
or postscript format.
Preparation: Before the laboratory session, read the C
program FahrToCelsius which is found as file
table.c in directory ~walker/assembly.
Steps for this Lab:
-
Focusing on this C program, compile the program to
assembly to determine what code is produced using the
gcc compiler.
-
The gcc compiler allows you to request one of several levels of
optimization of the code, using the -O option. E.g., for level 2
optimization, type:
gcc -S -O2 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:
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 13, 1999