Question: Study proc 2 . c and trace the program. What will be the output if you run the program? Compile and run proc 2 .
Study procc and trace the program. What will be the output if you run the program? Compile and
run procc in a terminal or any IDE and verify your answer.
Load procs in MARS. This is the MIPS version of procc Do not assemble and run this
program, as there are errors due to the misuse of registers. Study the MAIN function and discuss with
your partners about what it does compare it with the C version
When MAIN calls SUM, SUM knows where to return to Why? After SUM called SUB, what happens to the
address returning to MAIN? Discuss with your partners about how you would resolve this problem. Do
not attempt to fix it yet, as we have more problems to come.
The input argument n in function SUM is used to call the next function, SUB, as well as being added to
the return value. According to the register convention, the first argument of all function calls must be
stored in $a From line of procs the value in $a is no longer the same as the input argument
of SUM it has been changed to store input argument of SUB We can resolve this problem by saving the
original $a into a temporary register, but we may eventually run out of registers if our program is large.
Discuss with your partners about how you would resolve this problem. Do not attempt to fix it yet.
Have a look at line What happens to the original value in $s from MAIN after this statement is
executed? Is this a problem? Why? Discuss with your partners about how you would fix this problem.
Do not attempt to fix it yet.
Now we know that SUM needs to backup values before calling SUB. Insert prologue and epilogue into
the code so the program will run correctly. Hint: study function SUB, as it does not contain any errors
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
