Assignment 6, due Oct 3 (!!)

Part of the homework for 22C:60 (CS:2630), Fall 2011
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 stupid little SMAL Hawk subroutine:
    ; subroutine to add two numbers
    ADDTWO: ; conforms to standard Hawk calling conventions
            ;   given R3 = a, an unsigned integer
            ;   given R4 = b, an unsighed integer
            ;   returns R3 = a + b
            ADD     R3,R3,R4
    	JUMPS	R1
    

    A problem: Modify the above code so that it prints out its operands and their sum. For example, if the subroutine was called with the parameters 3 and 4, the output would be: 3+4=7. This should cause no observable change in the behavior of ADDTWO from the perspective of programs that call it. (1.0 points).

    Note: To solve this problem within the standard Hawk calling conventions, you will be forced to create and use an activation record for ADDTWO. No main program should be turned in, but you are welcome to write one to test your code.

  2. Background: Here is a really stupid implementation of multiplication:
    unsigned int times( unsigned int a, unsigned int b) {
      /* return the product of two numbers, a and b */
      unsigned int p;
      if (a == 0) {
        p = 0;
      } else {
        p = times( b, a - 1 );
        p = p + b;
      }
      return p;
    }
    

    a) The correctness of this code is not trivial. Consider the call times(5,0). Why does the code work without a check for the second parameter equal to zero? (0.5 points)

    a) Write SMAL Hawk assembly code that exactly preserves the logic of the above multiplication routine. (1.5 points)

    Note: Again, no main program should be turned in, but you are welcome to write one to test your code.