Assignment 5, due Feb 22

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: In the notes for Chapter 5, a call to the PUTS monitor routine was given as:
    ;  --- begin aplication code ---
            LIL     R3,HELLO
            LIL     R1,PUTS
            JSRS    R1,R1        ; puts(HELLO)
    ;  --- end aplication code ---
    

    In class, the following alternative code was given that works equally well:

    ;  --- begin aplication code ---
            LIL     R3,HELLO
            LIL     R4,PUTS
            LIL     R1,RET
            JUMPS   R4           ; puts(HELLO)
    RET:
    ;  --- end aplication code ---
    

    A Problem: Define a macro called MYJSRS that uses the combination of LIL and JUMPS that was given in class, so that this code would work:

    ;  --- begin aplication code ---
            LIL     R3,HELLO
            LIL     R4,PUTS
            MYJSRS  R1,R4        ; puts(HELLO)
    ;  --- end aplication code ---
    

    Feel free to test your result, but all you need to turn in is the 4 lines of SMAL code that define the macro. Handwriting is good enough, if it is legible. (0.5 point)

  2. Background: The Hawk monitor passes two parameters to the main program when it calls it: It passes the width of the terminal window in R3, and the height in R4 (or at least, the height of what's left in the bottom of the window after it filled the top with the registers and whatnot that it displays).

    You can take for granted the fact that the instruction SR R5,1 will divide the value stored R5 by 2, and this works for any register,

    A Problem: Write SMAL Hawk code to output an x at approximately the center of the screen. This will require calls to two monitor routines. One to set the screen coordinates and one to output the character. This takes a total of about 7 machine instructions, excluding the 'boilerplate' code from the main program. Turn in just those 7 instructions (legible handwriting is good enough), but you are free to substitute your code into the Hello World program in order to test it. (0.7 point)

  3. Background: Look at the last example given in Chapter 5 of the notes. There are two branch instructions there, BGE ENDLOOP and BR LOOP

    A Problem: Give the binary code for these two instrucitons. (0.8 points, 0.4 each)

    Suggestion: Do it by hand first! Then check your work by assembling the code.

  4. Background: Consider this bit of code in a high-level language:
    	if (a < b) {
    		c = a;
    		a = b;
    		b = c;
    	}
    

    A Problem: Give an equivalent fragment of SMAL Hawk code, assuming that the variable a is R3, b is R4, and c is R5. this code takes about 5 machine instructions. (0.5 points)

  5. Background: There are 4 commonly used Hawk instructions for loading registers from memory: LOADS, LOADSCC, LOAD and LOADCC. Broadly speaking, these four alternatives reflect just two features that may either be used or unused.

    a) One feature has to do with the addressing mode. What are the two alternatives? (0.3 points)

    b) What is the other feature? What are the two alternatives? (0.2 points)