Assignment 4, Solutions

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

  1. Background: Consider the following code, written in SMAL for the Hawk computer:
    	USE	"hawk.h"
    
    	LIS	R15, 1
    	LIS	R14, 2
    	ADD	R13, R14, R15
    	MOVE	R12, R14
    	ADDSI	R12, 2
    	ADDI	R11, R14, 3
    	LIL 	R10, #FFFFFF
    	ADDSI   R10, 7
    	ORIS	R9,  7
    

    All of the instructions used here are discussed in Chapter 4 of the notes, and for all of them, the chapter shows both the (somewhat) human readable form of the instructions and the binary, as well as showing the form of the assembly listing when working with these instructions.

    a) Assemble this code into memory. Show the contents of memory as a column of 11 16-bit halfwords in hexadecimal, with the address of each halfword written off to the side. (1 point)

    Hint: The first entry in this column would be 00: 01DF

    Suggestion: As in last week's assignment, do it by hand first, converting the code to binary and then hexadecimal, and then shuffling the pieces into the correct order. Then check your work by assembling this code using the SMAL assembler and then loading the resulting object file into the Hawk emulator to see what data actually lands in memory. (You do not need to link this code.) If you do this both ways, you prove that you understand what the assembler did and you check your work.

            00: 01DF
            02: 02DE
            04: EF3D
            06: FEFC
            08: C21C
            0A: 6EFB
            0C: 0003
            0E: FFEA
            10: FFFF
            12: C71A
            14: 07C9
    

    b) After these instructions are executed, what data registers (R1 through R15) are changed and what are their new values? (1 point)

    Suggestion: Do it by hand first! Then check your work by loading the object code in the Hawk emulator and using the s command (single step) to run each of the 9 instructions in succession. If you do it both ways, you will both maximize your learning and be able to check your work.

            R9: 00000007
            RA: 00000006
            RB: 00000005
            RC: 00000004
            RD: 00000003
            RE: 00000002
            RF: 00000001
    

    c) The program above begins with a line saying USE "hawk.h". This causes the assembler to read the file hawk.h, and since that file is not defined in your directory, it looks for it in the hawk library. A copy of that file is available on line, at
    -- http://homepage.cs.uiowa.edu/~dwjones/arch/hawk/hawk.txt
    Take a look, and see if you can find all of the different macro calls that are executed in order to assemble the third instruction of the file, ADD R13,R14,R15. List the macro calls involved, giving, for each, the name and the values of the parameters. (0.5 points)

    ADD R13,R14,R15 is a macro call. This calls qNZREGq R14, qNZREGq R15, and qTHREEREGq #3000,R13,R14,R15.

  2. Background: Consider this brief Hawk program, loaded into memory starting at location zero:
    	JSRS	R1,R1
    	LIS	R1,3
    

    Assume that all registers (including the program counter) initially contain zero, as if the machine was just started.

    A problem: How many fetch-execute cycles must finish before register 1 is assigned the value 3? Equivalently, how many times must you hit the emulator's s (single step) key before R1 is set to 3?

    Hint: The point of this problem is to get you to look into Chapter 5 before Friday's lecture. As usual, consider solving this problem on paper and then checking your work using the Hawk emulator.

    Three.

    1. The JSRS swaps R1 with PC. Because R1 was zero, this sets PC back to zero. This sets R1 to 2.
    2. The JSRS swaps R1 with PC again. Because R1 was 2 this time, this sets PC to 2. It also sets R1 to 2 again.
    3. The LIS finally sets R1 to 3.