Assignment 5, due Feb 21

Part of the homework for 22C:60 (CS:2630), Spring 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 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: Consider this fragment of SMAL assembly code based on instructions introduced in Chapter 5 of the notes:
            LEA     R1,X
    X:	JSRS	R1,R1
    	BR	X
    

    a) Give the result of assembling this code as a sequence of address-value pairs, one per line, where each value is a halfword given in hexadecimal. Assume you are starting at address zero. (0.4 points)

    Hint: You will learn the most from this exercise by doing it by hand, first, using the Hawk Manual and the material in Chapter 5 of the notes, and then check your work by using the SMAL assembler.

    b) What value does the LEA instruction load into R1? (0.2 points)

    c) How many times is the JSRS instruction executed before the first time the BR instruction is executed? (0.4 points)

    Hint: Again, work this out from the manual and Chapter 5, and then check your work by loading and running the code on the Hawk emulator, using the s command (single step) to advance the emulator one instruction at a time to see what it does.

  2. Background: Consider this fragment of the Hello World program from Chapter 5 of the notes:
    ;  --- begin aplication code ---
            LIL     R3,HELLO
            LIL     R1,PUTS
            JSRS    R1,R1        ; puts(HELLO)
    ;  --- end aplication code ---
    

    At the start of this code, R3 holds the width of the display area, R4 holds the height. Note that the PUTAT monitor subroutine sets the coordinates for the next output. Note also that the instruction SR r,1 will divide any register r by two (you can look it up if you want, but all you need to know right now is that it works).

    A problem: Modify the hello world program so that the H of the word Hello is displayed at the center of the display area of the screen. You need not run the program (but of course, you can check your work by running it.) Do not turn in the entire program. Just turn in the part of the code between the begin application code and end application code comments. Handwritten solutions are welcome, but as in all programming, legibility is important. Poorly formatted code will be penalized proportionally to its degree of unreadability. (1.0 points)

  3. Background: In high-level programming languages, you can write code something like this:
        if ((a >= 10) && (a < 20)) a = 0;
    
    Assume that R3 is being used to hold the value of the variable a.

    A problem: Write a fragment of SMAL Hawk code that is equivalent to the above. (1.0 point)

    Hint: It will involve at least two comparisons, at least two branches, some labels and the code for the assignment a=0.