ECEn 424 Homework Set #4

Upload a pdf file containing your solutions to the problems below to Learning Suite before 11:00pm on the assigned date.

  1. Problem 4.45

  2. Problem 4.46

  3. Problem 424-2:
    You are to determine how big stacks can grow to be.

    For part A, write C code that calls a single function with a large stack-allocated array, and see how big that array can be.

    For part B, write C code that calls a function recursively, and see what the maximum recursion depth is.

    For both parts A and B, what error message do you get when you overflow the stack? Do you get different results if you run on a different machine (different OS or different version of Linux)? Do you get different results compiling for the IA32 ("-m32") or for the x86-64 ISA (with "-m64")?
    If you are running the bash shell (pretty common on Linux and Macs), you can find the default stack size (and other system information) by typing "ulimit -a". (If you are running the tcsh shell, there is a "limit" command that gives similar but not identical functionality.) Does the listed size agree with the results of your experiments? The "ulimit" command also allows you to set the stack size with the "-s" option. (You can readily find the details with an internet search.) Try your experiments again after increasing the stack size. Did it do what you expected? (If you can't get the ulimit/limit commands to work, make a note of this in your submission.)
    Finally, try compiling with the "-Os" optimization flag for gcc. (It tells the compiler to optimize for size but not at the expense of speed.) See if this affects the recursion depth you observed for a given stack size.
    The code here is intended to serve as a starting point. Make sure you understand what it is doing if you use it. Note that it just tries sizes and recursion depths that are powers of two. You'll have to plug different values in for N and M to see where it breaks.

Clarifications

Problem 4.45: No C code or execution results are required.

Problem 4.46: No C code or execution results are required.

Problem 424-2: (determining the stack size): Include the source code you use and some screen shots or results from running it with a few different values. Write a paragraph for each part (A and B) explaining what you discovered. Are the results for both parts consistent with each other? Are results consistent for different operating systems and for both the IA32 and x86-64? Be sure to mention the impact of the -Os compiler flag and changing the stack size with ulimit. The -m32 flag is no longer an available option on the CAEDM SPICE machines or the latest Mac operating systems. In order to use the -m32 flag you will need to install additional libraries. Try this on your personal machines if you have the option. Otherwise, complete as much of the problem as you can without the -m32 flag.


Last updated 11 Febuary 2020