Use RIPES.me program to write code and DO NOT USE $ signs! Write a program
that prints the string, "This program computes 2^(^())3dots..." computes 2^(3) recursively, and then prints the result. Again, for this program, 2 and 3 will be hard-coded into the assembly, but the result will actually be computed.
, use the appropriate system calls to print the string, the output number, and to correctly exit with status 0 . Setup the code with the appropriate .data and .text sections.
For computing 2^(3) you should define a function pow (a,b) that implements the following recursive algorithm.use the jal instruction to call your pow function. To pass arguments to the function you should use the a0 and a1 registers. To return the final answer, you should use the a0 register.
However, this function is recursive, which means the intermediate values a 0 and a 1 will be overwritten. To avoid this problem, use the function call stack by utilizing the stack pointer sp
Increment the stack pointer to make room for the values of a 0 , a 1, and ra before calling pow (). Use the sw instruction to put the values of a0,a1, and ra into memory "on the stack" based on where the sp is pointing.
Call pow ( )
When pow ( ) returns, move the value out of a 0 into a different register (recommended: any of the "temporaries"). Then, use the 1w instruction to retrieve the old values of a0,a1, and ra from "the stack" (memory) based on where sp is pointing. Finally, return sp to it's original position.
After doing all of this, you should have the value of pow ( a,b-1 after the recursive call has been finished in a temporary register (e.g., t2).
ans =a**pow(a,b-1)
Finally, compute the multiplication and store the result in a 0 to be returned.
After you have the code working for a=2 and b=3, change the values to a=9,b=8 and make sure the program still works correctly.
Write a program that prints the string, This program computes 2^3.. " computes 2^3 recursively, and then prints the result. Again, for this program, 2 and 3 will be hard-coded into the assembly, but the result will actually be computed.
, use the appropriate system calls to print the string, the output number, and to correctly exit with status 0. Setup the code with the appropriate .data and .text sections.
For computing 2^3 you should define a function pow (a, b) that implements the following recursive algorithm.
powa, b{ ifb==0{ return 1 }
ifa==0 return 0 }
ans =a* powa, b-1) return ans
}
use the j a 1 instruction to call your pow function. To pass arguments to the
function you should use the a 0 and a 1 registers. To return the final answer, you should use the a0 register.
However, this function is recursive,which means the intermediate values a 0 and a 1 will be overwritten. To avoid this problem, use the function call stack by utilizing the stack pointer sp
Increment the stack pointer to make room for the values of a0, a1, and ra before calling pow () . Use the sw instruction to put the values of a0, a1, and ra into memory on the stack based on where the sp is pointing.
Call pow)
When pow returns,move the value out of a0 into a different register (recommended: any of the temporaries. Then, use the 1w instruction to retrieve the old values of a0, a1, and ra from the stack (memory) based on where sp is pointing. Finally, return sp to it's original position.
After doing all of this,you should have the value of pow (a, b-1 after the recursive call has been finished in a temporary register (e.g., t2)
ans= a *powa, b-l
Finally, compute the multiplication and store the result in a O to be returned.
After you have the code working for a=2 and b =3, change the values to a=9, b=8 and make sure the program still works correctly.