Question: Write the RISC - V assembly code for the following function, then in main call the function power: int power(int x, unsigned int y) {

Write the RISC - V assembly code for the following function, then in main call the function power:

int power(int x, unsigned int y)

{

int res = 1; // Initialize result

while (y > 0)

{

// If y is odd, multiply x with result

if (y & 1) res = res * x;

// n must be even now

y = y >> 1; // y = y/2

x = x * x; // Change x to x^2

} return res;

}

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!