This assignment has three problems. The first problem asks you to use information from the assembly language listing of a C program to determine what the C program is doing. The second problem asks you to use the assembly language listing of a C program to explain what "tail recursion optimization" does. The third problem asks you to analyze a C program that has a tail recursive function and explain why the compiler cannot use "tail recursion optimization".
1.) For this problem you MUST use the LccWin32 C compiler.
Download this C program, ascii.c. Compile (using lcc) and run the program and notice its output. Now make the change of
Now make a second change in the program, change the expression
2.) For this problem you MUST use the MinGW gcc compiler. Download this C program tail-factorial.c. This program is a tail recursive version of the factorial function. At a command prompt, use the command
Now use the command
Use the two assembly language listings to explain why the first compiled version of the program crashed and why the second one does not. Explain as carefully as you can how the compiler changed the compiled version of the program to make it "properly" tail recursive.
3.) Download this C program weird-tail-recursion.c. You can compile and run this program with any C compiler. This program uses tail recursion but a compiler cannot use "tail recursion optimization" with this program. Explain why this is true. You do not need to look at the assembly language listing to answer this. Just study the C code carefully and think about how the program works. Draw a picture of what several stack frames look like after several recursive calls of the procedure |