Assignment 4, due Jun 24

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

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated, and unless there is what insurance companies call "an act of God" - something outside your control; the only exceptions to this rule will be by advance arrangement.

Remember, summer session goes very quickly! You will fall behind very quickly if you do not keep up with the work.

 
 

  1. Background: Consider this SMAL Hawk program:
            TITLE   "???"
            S       START
            USE     "hawk.macs"
            USE     "monitor.h"
            COMMON  STACK,#1000
    PSTACK: W       STACK
            ALIGN   2
    START:  LOAD    R2,PSTACK
            LOAD    R1,PDSPINI
            JSRS    R1,R1
            LIS     R8,' '
            LIS     R9,0
    LOOP1:  LIS     R3,0
            MOVE    R4,R9
            LOAD    R1,PDSPAT
            JSRS    R1,R1
            LIS     R10,0
    LOOP2:  CMPI    R10,16
            BZS     EXIT2
            MOVE    R3,R8
            LOAD    R1,PDSPCH
            JSRS    R1,R1
            ADDSI   R8,1
            ADDSI   R10,1
            BR      LOOP2
    EXIT2:  ADDSI   R9,1
            CMPI    R9,6
            BLT     LOOP1
            LOAD    R1,PEXIT
            JSRS    R1,R1
            END
    

    a) What does this program do? Give a one sentence answer!

    Recommendation: Figure it out by reading the code, and then try running the code and see if what you figured out is correct. There is a clean short one sentence answer. (1/2 point)

    b) The code given here has a meaningless title, no blank lines and no comments at all. Reformat the program to improve readability, add an appropriate title, and add appropriate comments. (1 point)

     
     

  2. Background: Addition and multiplication in the domain of the natural numbers are sometimes defined as follows:

    plus( i, 0 ) = i
    plus( i, j ) = plus( i, j-1 )+1 when j is nonzero.

    times( i, 0 ) = 0
    times( i, j ) = plus( times( i, j-1 ), i ) when j is nonzero.

    This definition reduces all addition and multiplication to incremet and decrement operations. This definition is also recursive.

    a) Convert this definition of the plus and times operators into a recursive function in a language such as C, C++ or Java. (1/2 point)

    b) Give the equivalent SMAL Hawk assembly code. (1 points)

    Note: All arithmetic should be done with ADDSI (but there is a remote possibility that you will also need some ADDI instructions). The only comparison instructions should be comparison with zero, which can be done by the Hawk TESTR instruction.