Question: USE MARS AND ASSEMBLY LANGUAGE FOR FOLLOWING: You are going to make a recursive procedure (a procedure that calls itself). This is conceptually very similar
USE MARS AND ASSEMBLY LANGUAGE FOR FOLLOWING:
You are going to make a recursive procedure (a procedure that calls itself). This is conceptually very similar except the program can have a fairly large stack. Lets say we have 3 programs. A calls B, B calls C, C calls D. A{ B()}; B{C()}; C{D()}; D{something}. The way this actually works is D finishes first, gets popped off the execution stack then C gets the result of D, finishes what it was doing, gets popped off, B gets the result of C, finishes, pops off the stack, then A gets the result of B and finishes.
Recursion is essentially the same, except its the same function, just with different parameters at each step. Well, hopefully. If you keep giving it the same parameters, youll get an infinite loop. We will make a simple recursive function, given two integers (s and f) we will have a recursive function that adds all of the integers from s to f Example in C#: int mySum (int s, int f){
if (s==f){
return f;
}
else{
return s+mySum(s+1, f);
}
}

You need to make this work (notice that $a0 and $a1 are never set)
The MIPS conversion of code above is: 1 mysum: 2 bne $a0, $al, ms_recurse 3 move $v0, $al 4 jr fra 6 ms_recurse: 7 sub $sp,$sp, 8 8 sw $ra, 0($sp) 9 sw $a0, 4($sp) 10 add $a0, $a0, 1 11 jal mysum 12 lw $a0, 4($sp) 13 add $v0, $v0, $a0 14 lw $ra, 0($sp) 15 add $sp, $sp, 8 16 jr $ra The MIPS conversion of code above is: 1 mysum: 2 bne $a0, $al, ms_recurse 3 move $v0, $al 4 jr fra 6 ms_recurse: 7 sub $sp,$sp, 8 8 sw $ra, 0($sp) 9 sw $a0, 4($sp) 10 add $a0, $a0, 1 11 jal mysum 12 lw $a0, 4($sp) 13 add $v0, $v0, $a0 14 lw $ra, 0($sp) 15 add $sp, $sp, 8 16 jr $ra
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
