I was in class and we have/are covering recursion in Assembly Language. I felt like I understood recursion, but the more people attempt to explain it to me, the more I feel distant from it.
Anyways, our last slide had a function (in C?) and the teacher said he will cover it in class but call on us students to show the rest of the class on the board. I felt like he was looking at me the whole time and I am terrified of looking stupid.
Can you guys help me write this code in MIPS and help me understand it? IDK if this is too hard
Write in MIPS Assembly Language that to find fix(i,x), where fix(i, x) is defined recursively as:
int fix(int i, int x) // assume i > 0, x > 0
{
if (x>0)
return fix(i,x-1);
else if (i>0)
return fix(i-1, i-1)+1;
else
return 0;
}
Thank you guys, my class is tomorrow and I still hope he never calls on me; but I would like to actually understand this material.
NOTE: This will be an in class exercise with 0 credit attached. I feel like everyone in the class already knows how to do this.
While I am against just giving the answer to homework problems, here is the equivalent function that will find
fix(i, x)
, complete with example call (this version is a little more efficient than the C version):And let this be a lesson to you to learn what functions do before attempting to code them :)