Lab Assignment--Process Memory
The purpose of this lab is to explore the memory associated with the user
process: text, data, and stack.
- Copy and paste the following source code:
- Compile and run the program.
Several addresses are output from the program including:
You may want to use a redirect to save the output for later.
- global variables
- static local variables
- heap variables
- Your task is to fill in addresses of the variables, and functions
to provide at least TWO examples of:
Fill in the following template:
- instuctions in machine code
- global initialized variables
- static initialized variables
- global uninitialized variables
- static uninitialized variables
- dynamically allocated variables
- local automatic variables from main
- local automatic variables from each of proc1 and proc2
To get an idea of what is expected, the following is an example run
with addresses of these components:
Please remember to include the "etext", "edata", and "end" addresses
Before continuing, run the program again and confirm that the output is the same.
As variables are added to the stack, do the addresses get smaller or larger?
Do variables stored on the stack ever have the same address as other variables? Why or why not?
Where would you expect variables (or arguments) in recursive functions to be stored (stack, heap, or other data segment)?
When you are finished step 8 below, comment on whether your expectations were correct or not.
Test your expectation by adding a recursive factorial function.
For instance, the factorial of 5 is represented by 5! and is calculated as
In the factorial function, you will print the address of the factorial function
and the address of the argument passed to it.
In main, you will prompt the user for what factorial they will want to calculate
and send that input as an argument to the function.
In main, you will also print the value returned from the factorial function.
The idea behind the recursive factorial function is the following:
|| if n = 0 (base case) |
|| if n >= 1 (recursive step)|
Submit 3 files to URCourses
- The code with the new recursive factorial function
- Note: the memory diagram will be at the top of this code
- Answers to questions 5, 6, and 7 (as a text file)
- Two sample runs of the recursive factorial function showing: