Laboratory Exercises For Computer Science 211

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 some or all of the following references.

Preparation: Before the laboratory session, read the C program FahrToCelsius which is found as file table.c in directory ~walker/assembly/pentium.

Steps for this Lab:

  1. Focusing on this C program, compile the program to assembly to determine what code is produced using the gcc compiler.

  2. Compile table.c to assembly language using the gcc compiler, and discuss how double precision floating point computations are handled.
  3. 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:

Note: 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.cs.grinnell.edu/~walker/courses/211.fa01/labs/lab.code-optimization.html

created October 1, 1997
last revised October 15, 2002
Valid HTML 3.2!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.