CS 220 - Homework 3 - Due Tuesday March 6

Computing xy recursively

Below is a beautiful algorithm in Python for computing xy recursively.

# pow(x,y) computes x raised to the y power.
# y is a non-negative integer
def pow(x,y):

  # Base case. x to the zero is 1
  if y == 0:
    return 1
    
  # if y is even compute x to the (y/2)
  # then multiply that result by itself.
  elif y % 2 == 0:
    tmp = pow(x,y/2)
    return tmp * tmp
  
  # if y is odd compute x times x to the (y-1)
  else:
    return x * pow(x,y-1)

Write a recursive MIPS function named pow that takes two integer parameters and returns xy using the recursive algorithm above. Your main program should prompt the user for an x and a y and then print the result back to the console.

Make sure that your program is recursive and that it calls itself using jal instructions and properly stores return addresses on the stack.

Requirements

  1. Your program must obey the MIPS calling conventions.
  2. Turn in a printout of your program at the start of class on Tuesday March 6.
  3. Email me a copy of your program as an attachment and make sure that the name of the file is username_hw3.s where username is your user name. Make sure the subject heading in the email says CS220 HW 3
  4. Your program should be neat and tidy. Make sure that there are no bad line breaks, lines that wrap around, etc. Make sure that indentation is consistent and that tab characters don't make the printout look messy.
  5. There should be a nice block comment at the top that has you name, the date, the homework assignment number (this is HW3). For example
    
          #--------------------------------------------------------
          # Name: your name
          # Date: 3/6/2012
          # Assignment: HW 3
          #
          #    This program computes the sum of the numbers below
          #    1000 that are divisible by 3 or 5 and leaves the
          #    result in register $t0.
          #--------------------------------------------------------