CS2208b Assignment 5 Solved

35.00 \$ 17.50 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

Description

5/5 - (1 vote)

QUESTION 1 (100 marks)

Recursion is a method where the solution to a problem depends on solutions to smaller instances of the same problem. A function is considered recursive if it calls itself.

The following function computes xn recursively, where x is an integer number and n is a non-negative integer number.

int power(int x, unsigned int n)

{

int y;

if (n == 0)Â Â  Â Â Â Â return 1;

if (n & 1)Â  Â  Â Â Â Â return x * power(x, n – 1);

else

{ y = power(x, n >> 1);Â  Â Â Â Â return y * y;

}Â  }

Draw a detailed flowchart and write an ARM assembly program to calculate xn using the above recursive function, where n is passed-by-value through the stack to the function and the returned value is stored in the stack just above the parameter. No other registers may be modified by the power function. Once the control is completely returned back from the function (i.e., after calculating xn), the returned value must be stored in a local variable (called result) in the main function. Your code should be highly optimized, i.e., use as little number of instructions as possible.

You should utilize a big enough stack so that you can calculate xn for various n values.

How many stack frames are needed to calculate xn, when n = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, and 12?

• cs2208-ass5-rfjhbt.zip