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
Get step-by-step solutions from verified subject matter experts
