Assignment 6, due Oct 3

Part of the homework for 22C:60, Fall 2008
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Remember to write your name on what you turn in! Homework must be turned in on paper and in class!

Homework

  1. Background: Consider the following Hawk program fragment that accesses two local variables (A and B) of the current subroutine.
            LOAD	R3,R2,A
            LOAD	R4,R2,B
    	STORE	R3,R2,B
    	STORE	R3,R2,A
    

    a) Concisely explain what this does to the values of the two variables. (0.2 points)

    b) Show the Hawk machine code resulting from assembling this code. Give your answer as a sequence of 8 halfwords, each expressed in hexadecimal. If any part of any halfword is unknown, use question marks for the hex digit corresponding to that part. (0.8 points).

  2. Background: Suppose the Hawk machine did not have a LOAD instruction, but just LOADS. Given one free register (for this question, use R1), you can rewrite any LOAD instruction as a sequence of an ADDI instruction and a LOADS instruction.

    Question: Write a macro MYLOAD such that MYLOAD a,b,c does exactly the same thing as LOAD a,b,c. (1.0 points)

  3. Background: Some machines have addressing modes that reference items on the stack. For example, the Rockwell Collins Advanced Architecture Microprocessor (perhaps the most important family of computers designed in Cedar Rapids, Iowa) has an add instruction that pops the top two items off the stack, adds them, and pushes the result. The AAMP call instruction pushes the return address on the stack, and the AAMP return instruction pops the return address from the stack and goes there.

    Problems: For each of the following, what sequence of Hawk instructions would you substitute for the given AAMP instruction? Use R2 on the Hawk as a stack pointer - it always points to the free word just beyond the stack top, and use R1 as a temporary if you need one.

    a) an AAMP add instruction. (0.3 points)

    b) an AAMP call instruction. Warning -- this is tricky. (0.4 points)

    c) an AAMP return instruction. (0.3 points)