Assignment 5, due Sep 26

Part of the homework for CS:2630 (22C:60), Fall 2014
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 DUE TO CLASS CANCELLATION: homework is to be turned in to the CS Department secretary, Room 14 MLH by noon, on Sept. 26. 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. A Problem: Consider this SMAL code, a fragment of a main program:
            LIS     R8,1
            LIS     R10,0
    L1:
            CMPI    R8,10
            BGT     L3
            LIS     R9,1
    L2:
            ADDSI   R10,1
            ADDSI   R9,1
            CMP     R9,R8
            BLE     L2
            ADDSI   R8,1
            BR      L1
    L3: 
    

    a) Reverse engineer this code and give equivalent code in a language like C, C++, Java or Python. Use the letters i, j, and k as variable names, and to the extent possible, write your code using for loops, while loops and similar high-level constructs. (1 point)

    b) What is the final value of the R10 at the time control reaches L3. (0.5 points).

  2. Background: Consider the file mp2data.a given in the assignment for MP2.

    A question: Why is an ALIGN directive required before ITEM2. (0.5 points)

    Suggestion: One way to think about this is to experiment. What happens if you leave the directive out? You can study the assembly listing for mp2data.a with and without alignment. Or, you can try linking it, with and without alignment, with your solution to MP2. The other option is to study what the ALIGN directive does and figure from that what the consequences are.

  3. Background: If a is the address of an array, where each array element has size s, then the address of array element i is a+si (assuming that the first element of the array is element zero).

    Note that the Hawk monitor contains TIMES and TIMESU subroutines for multiplying signed and unsigned integers.

    Note also that Section 14.1 of the Hawk manual gives efficient sequences of instructions for multiplying by small constants. Notably, to multiply the contents of register x by 4, use SL x,2. You do not need to know how this works for this problem, only that it works with no side effects (except on the condition codes).

    a) Given that the symbol ARRAY is the constant memory address of an a, an array of 4-byte words in memory, and given that the value i is stored in R8, write a fragment of SMAL Hawk assembly code to load the value of a[i] into R9. (1 point)