Assignment 6, due Feb 27

Part of the homework for CS:2630, Spring 2015
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: Suppose A is a constant, declared with a SMAL statement like:
         A       =       #12345
    

    Suppose B is a constant, declared with a SMAL statement like:

         B:      W       #1234567
    

    Suppose C is a global variable, declared with a SMAL statement like:

                 COMMON  C,4     ; an integer
    

    Suppose D is a local variable, declared with a SMAL statement like:

         D       =       8       ; an integer
    

    A problem: Write SMAL Hawk code to compute the sum of the values of A, B, C and D. If you were writing this in C or Python, the solution might be as simple as A+B+C+D because the language keeps track of the types of the operands. In assembly language, you might well need to use a different addressing mode for each operand. (1.2 points)

  2. Background: The code for the Fibonacci function discussed on Feb. 18 is only partly developed. See this code. Even though this code is only beginning to be fleshed out, it contains one clearly sub-optimal bit of code.

    a) Identify the sub-optimal code. You may do this by quoting the code, along with the lines immediately before and after the less than optimal part. (0.5 points)

    b) Optimize the suboptimal code. Show your result by giving the text you improved along with the lines immediately before and after it. (0.5 points)

  3. Background: Refer to Homework 5, problem 1. That problem, in parts a) through e), walked you through writing the code to do puts(array[i]->text working with the data structure from machine problem 1. The note said that we have not covered enough to finish writing mp1.a because we have not yet discussed how to load and store halfwords.

    As it turns out, the keys to this problem are in Chapter 7, which you should start reading before the due date for this assignment. To help motivate that, consider the following question, which would have made a nice part f) for Homework 5, problem 1.

    a) Given that R10 points to one record, that is, R10 holds the value of array[i], write SMAL Hawk code to load the value of the X field of that record (array[i]->x) into R3. (0.4 points)

    b) Given that R10 points to one record, as above, write SMAL Hawk code to load the value of the Y field of that record (array[i]->y) into R4. (0.4 points)

    Having completed both of the above, you could now write a call to putat() in order to set things up to output the string at the right place on the screen.