Laboratory Exercises For Computer Science 211

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:

  1. 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.

  2. 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
    
  3. 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:

Notes:
  1. 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.

  2. 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 1, 1997