Question: MIPS assembly language Computing x^y recursively Below is a beautiful algorithm in Python for computing x^y recursively. # pow(x,y) computes x raised to the y

MIPS assembly language

Computing x^y recursively

Below is a beautiful algorithm in Python for computing x^y 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) 

a) Write a recursive MIPS function named pow that takes a single-precision floating point number (x) and a 32-bit non-negative integer (y) and returns xy using the recursive algorithm above. x will be passed in $a0, and y in $a1. The return value should be placed in $v0.

b) We've seen the fact function in class. Write a recursive MIPS function named fact that takes a 32-bit non-negative integer (x) and returns x! using a recursive algorithm. x will be passed in $a0. The return value should be placed in $v0.

Make sure that your subroutines are recursive and that they calls themselves using jal instructions and properly stores return addresses on the stack.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!