This document discusses parameter passing through the stack and recursion. It provides an example of a recursive factorial procedure that passes the parameter N down the stack on subsequent recursive calls, decrementing it by 1 each time until the base case of N=1 is reached. It then returns back up the stack multiplying the intermediate results to calculate the final factorial value. The homework is to review an example of finding the maximum value on page 359.
Original Description:
Original Title
COAL Lec 15 Parameter Passing through Stack and Recursion
This document discusses parameter passing through the stack and recursion. It provides an example of a recursive factorial procedure that passes the parameter N down the stack on subsequent recursive calls, decrementing it by 1 each time until the base case of N=1 is reached. It then returns back up the stack multiplying the intermediate results to calculate the final factorial value. The homework is to review an example of finding the maximum value on page 359.
This document discusses parameter passing through the stack and recursion. It provides an example of a recursive factorial procedure that passes the parameter N down the stack on subsequent recursive calls, decrementing it by 1 each time until the base case of N=1 is reached. It then returns back up the stack multiplying the intermediate results to calculate the final factorial value. The homework is to review an example of finding the maximum value on page 359.
Parameter through Stack • BP register • RET n PROCEDURE FACTORAL (input: N, output: Result) If N = 1 then Result = 1 Else call FACTOTAL (input: N-1, output: Result) Result = N * Result END_IF RETURN Home work • Find MAX example on page 359