Assignment 05

Contents:

  • Overview
  • Internet Requirements
  • Practice Problems
  • Problems to be Submitted
  • Extra Credit

  • Overview

    Topic: Program Translation
    Related Reading: Ch. 5.4 of [Br] and Mod. 6.4 of [DH].
    To a lesser extent: Ch. 5.1 of [Br] and Mod. 6.1, 6.3 of [DH].
    Due: 8pm Monday, 15 October 2001

    This assignment will use the "Rosetta" program provide in Module 6 of the Decker/Hirshfield text. The practice problems will include an introduction to this software.

    Warning: For larger expressions and longer programs, the software scrolls down as needed. There are scrollbars in the windows which appear to imply that the user is able to scroll back up to the top, however it seems that these scrollbars do not work properly. Just keep this in mind if you play with larger examples.


    Internet Requirements

    You will need an internet connection at time of submission, and either the text's CD-ROM or an internet connection while working on the assignment.

    Practice Problems

  • Lab 6.2 (p. 225-227 of [DH])
  • Lab 6.3 (p. 228-229 of [DH])
  • Lab 6.4 (p. 230 of [DH])

  • Problems to be Submitted (20 points)

    1. (10 points)
      See if you can match parse trees with their corresponding statements. For each of the parse trees below, write the statement that it represents. You may choose to use Rosetta to confirm your answers if you wish (though you do NOT need to submit your Rosetta work).

    2. (10 points)
      For each of the PIPPIN code segments below, find an arithmetic statement that corresponds to it. You may choose to use Rosetta to confirm your answers if you wish (though you do NOT need to submit your Rosetta work).

      1. LOD #3
        MUL Y
        ADD X
        STO W
        

      2. LOD X
        DIV Y
        STO T1
        LOD #3
        SUB T1
        STO Z
        

      3. LOD #2
        MUL Y
        STO T1
        LOD Z
        DIV #3
        STO T2
        LOD T1
        SUB T2
        STO X
        

      Overall, please type your answers to all of these questions in a single text document to be submitted.


      Extra Credit (up to 4 points)

      Code Optimization: The primary goal of a compiler is to take a program in a high-level language, and convert it to a correct machine language program. A secondary goal, however, is to try to produce the most efficient machine code possible. That is, two different machine language programs may solve the same task, but one may do so with fewer overall instructions, or use fewer memory locations for temporary storage.

      For example, if you look carefully at Rosetta's code generation, you will notice that it generally uses memory locations W,X,Y,Z to signify the original inputs and the final results. It uses 'registers' T1, T2, T3, T4 at times to temporarily store a partial computation.

      For extra credit, we are going to examine code for the expression:

      W = (X/3) - ( (Y-3) / (Z+2) )
      
      If you type this expression into Rosetta and allow it to generate code, you will notice that the code makes use of three extra registers at various times: T1, T2, T3. This is somewhat wasteful. With care, it is possible to design PIPPIN code for evaluating this expression which only uses one such register. This can be done by carefully restructuring the order of various computations along the way.

      For extra credit, try to write your own PIPPIN code for evaluating the given expression using as few registers as possible. We will give you two points if you find a solution which optimizes Rosetta's solution, using only two registers rather than three. We will give you four points if your solution uses only one register!

      Save your PIPPIN code in a file named "Optimized" to be submitted.

      Note: code optimization is only useful if you are still producing code which produces the correct final result. No points will be given for code which does not correctly evaluate the original expression.


      comp150 Class Page
      mhg@cs.luc.edu
      Last modified: 5 October 2001