Question: Prob 1 LC3 If we implement a runtime stack using an array, we dont need a dynamic link pointer to the activation record, so all

Prob 1 LC3

Prob 1 LC3 If we implement a runtime stack using an array,

If we implement a runtime stack using an array, we dont need a dynamic link pointer to the activation record, so all we need are spaces for parameters, the return value, the return address, and local variables. A sketch of the program from Problem 1 into low-level pseudocode follows. You are to implement the pseudocode in LC3 assembler. (You dont have to stop at locations A and B in Problem 1.) When calling RecSum, the stack should have S as the top element and N just below it. (Ill write this as N S [top to the right].) RecSum should begin by completing the activation record (stack = N S [space for result] R7) * . When RecSum returns, the stack should be N S result (because R7 was popped off to restore it).. The top-level call to RecSum is done by Sum, which is called by the main program. Sum should initialize the stack, set it to R7 N 0 and call RecSum. When RecSum returns, Sum should pop the returned value off the stack and return it (after clearing out the stack). Note: RecSum is written as a tail-recursive routine: Once the base case figures out what it wants to return, all of the recursive calls just return that same value

(***STUB*** to fill the code for .asm file )

we dont need a dynamic link pointer to the activation record, soall we need are spaces for parameters, the return value, the return

main: N=3; S = Sum (N); Sum (N): return RecSum (N, 0) RecSum(N, S): if Ns0, return value = s; /*Location A/ return else return value RecSum(N-1, S+N) /* Location B * return main: N=3; S = Sum (N); Sum (N): return RecSum (N, 0) RecSum(N, S): if Ns0, return value = s; /*Location A/ return else return value RecSum(N-1, S+N) /* Location B * return

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!