Assignment 12, due Jul 26

Part of the homework for CS:2630, Summer 2018
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 (Tuesday or Thursday). 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: The Sparrowhawk instruction set is a subset of the Hawk instruction set. It contains most of the 16-bit short instructions of the Hawk, but none of the 32-bit long instructions. So, it has LIS but not LIL and it has LOADS but not LOAD. If you write USE "sparrowhawk.h" instead of USE "hawk.h" the assembler will allow you assemble code for the Sparrowhawk. If, before the USE directive, you define the symbol STRICTSPARROW, the assembler will rigidly confine you to the Sparrowhawk instruction set.

    If you leave out the definition of STRICTSPARROW, the assembler will define macros for the Hawk instructions, but these are macros. For example, if you write LEA R3,R2,LOCALVAR a macro like the following might be called:

            MACRO LEA =dst,=x,=const
              LIS  R1,const >> 8
              ORIS R1,const & #FF
              PLUS R1,x
              MOVE dst,R1
            ENDMAC
    

    The above definition ignores the possibility of PC-relative addressing and it assumes that R1 is available as a temporary for address computation.

    You can examine the entire un-simplified Sparrowhawk macros in the headers download collection on the course home page.

    a) Write similarly simplified macro for LIL. As with the code given above, ignore the possibility of external or relocatable operands. (0.5 points)

    b) Explain why the code for LEA given above uses PLUS instead of ADD. (0.5 points)

  2. Background: On the Hawk, an attempt to execute an undefined instruction causes an instruction trap, transferring control to address 2016. Consider installing the shortest possible trap service routine at that address:
    .       =       #20
    	RTT
    

    a) Give the smallest possible Hawk main program that installs this trap handler and then tests it with an undefined instruction. (Hint: The main program contains just the undefined instruction; the total amount of assembly language involved, including the above, is under 10 lines of code. (0.3 points)

    b) What happens when you run it? (Try single-stepping it so you can see what it does in some detail.) (0.2 points)

    c) Write the shortest trap handler you can that increments the trap program counter by 2, (leaving all the other registers unchanged) and then returns from trap. This trap handler converts all undefined instructions into no-ops equivalent to the built in NOP instruction. (A suggestion: Try it and see what happens.) (0.5 points)

  3. Background: Suppose you need to turn on the Hawk MMU. In theory, the following code should do this:
            CPUGET  R3,PSW
    	SUB	R0,R3,R3
    	ADJUST  R3,CMSB
    	CPUSET	R3,PSW
    

    If there is an MMU included in the Hawk, this code should cause an immediate MMU trap (trap to locaiton 4016), so there is obviously more to the story.

    a) What does the two instruction sequence SUB followed by ADJUST above do? A complete answer must go into enough detail to explain why it works. (0.5 points)

    b) What should be done before turning on the MMU in order to prevent the trap caused by the above instruction sequence. (0.5 points)