UP | HOME

HW22
COP-3402

  1. Are function-local variables (auto in C) allocated at compile-time or run-time?
  2. If some function definition has a local variable x, will that variable always be assigned a single memory location in any possible program that has such a function?
  3. The following are the contents of a stack frame, label which ones are caller created and which are callee created in the x86 64 System V ABI:
    • Callee-saved registers
    • Stack parameters
    • Return address
    • Local variables
    • Register parameters
    • Old base pointer
  4. What register in the x86 64 System V ABI is meant to hold a pointer to the currently-executing function's stack frame?
  5. What is the greatest number of active stack frames that will exist in memory at one time for the factorial function in the following program?

    #include <stdio.h>
    
    int factorial(int n) {
      if (n < 2) {
        return 1;
      } else {
        return n * factorial(n - 1);
      }
    }
    
    int main() {
      int n = 5;
      printf("factorial(%d) = %d\n", n, factorial(n));
    }
    

Author: Paul Gazzillo and Brent Pappas

Created: 2026-07-19 Sun 09:01

Validate