Assignment 6, due Oct 1

Part of the homework for 22C:60, Fall 2010
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always write your name legibly as it appears on your University ID and on the class list!

Homework

  1. Background: Here is the mp1test program, with some unfinished pieces in it:
            TITLE   "mp1test.a, test program for MP1 by Douglas Jones"
            S       START
            USE     "hawk.macs"
            USE     "monitor.h"
            EXT     UNUSED
            EXT     ROOT
    
    ; description of the structure of each node:
    LEFT    =       0
    RIGHT   =       4
    TEXT    =       8
    
    ; activation record structure for TRAVERSE
    NODE    =       4
    ARSIZE  =       ????(a)????
    
    TRAVERSE:
            STORES  R1,R2
            TESTR   R3
            BZS     TRAVQT          ; if node not null
            STORE   R3,R2,NODE
    
            LIS     R3,'('          ;   print '('
            ADDI    R2,R2,ARSIZE
            LIL     R1,DSPCH
            JSRS    R1,R1
            ADDI    R2,R2,-ARSIZE
    
            LOAD    R3,R2,NODE      ;   traverse(node->left)
            LOAD    R3,R3,LEFT
            ADDI    R2,R2,ARSIZE
            JSR     R1,TRAVERSE
            ADDI    R2,R2,-ARSIZE
    
            LOAD    R3,R2,NODE      ;   print(node->text)
            ?????(b)?????
            LIL     R1,DSPST
            JSRS    R1,R1
            ?????(b)?????
    
            LOAD    R3,R2,NODE      ;   traverse(node->right)
            ?????(c)?????           ;   something big is missing here
    
            ?????(d)?????           ;   something else big is missing here
    
    TRAVQT:                         ; endif
            ?????(e)?????           ; return
    
    ; the program starts here!
    START:  LIL     R2,UNUSED       ; set up the stack
                                    ;  --- begin aplication code
            LIL     R1,DSPINI
            JSRS    R1,R1           ; initialize the display
    
            LIL     R3,ROOT
            JSR     R1,TRAVERSE     ; traverse the tree
    
                                    ;  --- end aplication code
            LIL     R1,EXIT
            JSRS    R1,R1           ; stop!
    
            END
    

    The problem: Fix the above code. Several small pieces have been deleted. If you correctly repair the code, it will work as a test program for MP1. Comments in the code indicate each deletion of one or more lines. Parts a, b, c, d and e above are indicated by comments in the code. (0.4 points each, for a total of 2 points)

  2. Background: Chapter 6 discusses numerous approaches to optimization.

    The Problem: Apply all of them that you can to your solution to problem 1. (1 point)