Assignment 6, due Mar 1

Part of the homework for 22C:60 (CS:2630), Spring 2013
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!

  1. Background: As announced in class, and as recommended by the department of computer science, this question is offered as an incentive-reward for those who attended the University of Iowa Computing Conference:

    The following countries have populations between one and one-and-a-half million people (listed in order of increasing population): Timor-Leste, Swaziland, Bahrain, Mauritus, Estonia, and Trinidad and Tobago.

    a) One of these countries was mentioned during the Friday evening keynote address. Which one? (0.2 points)

    b) What subject was being discussed when that country was mentioned. (0.2 points)

  2. Background: Consider the following fragment of high-level language code:
            a = b;
    

    For each of the following, write a fragment of SMAL Hawk code that is equivalent to the above.

    In each case, assume that registers 3 to 7 are currently unused and therefore available for use as scratch registers and that register 2 points to the base of the current activation record. You may assume that the assembly language symbol A has been defined appropriately to give the address of the high-level language variable a and that the symbol B has been defined appropriately to give the address or value of associated with the high-level language identifer b.

    a) The variable a is a statically allocated global variable. the variable b is a local variable of the current subroutine (0.3 points)

    b) The variable a is a local variable of the current subroutine and the constant b has an unknown 32-bit value. (0.3 points)

  3. Background: Here is a classical way to multiply two non-negative integers:
    int times( int a, int b ) {
            if (a == 0) {
                    b = 0;
    	} else {
    		b = times( b, a-1 ) + b;
    	}
            return b;
    }
    
    The following is an incomplete translation of this to SMAL Hawk code:
            -- missing definitions and code --
            TEST    R2,A
            BNE     TELSE
            LIS     R3,0
            STORE   R3,R2,B
            BR      TENDIF
    TELSE:
            LOAD    R3,R2,B
            LOAD    R4,R2,A
            ADDSI   R4,-1
            ADDI    R2,R2,ARSIZE
            JSR     R1,TIMES
            ADDI    R2,R2,-ARSIZE
            LOAD    R4,R2,B
            ADD     R3,R3,R4
            STORE   R3,R2,B
    TENDIF:
            LOAD    R3,R2,B
            LOADS   R1,R2
            JUMPS   R1
    

    a) The above assembly code is completely free of comments! Write clear concise comments that cleanly connect the assembly code to the high-level language code from which it was derived. (1 point)

    b) Provide the missing definitions and code. (1 point)