Course Homepage

HW22

  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. Label which of the following stack frame elements are caller created, and which are callee created, in the x86 64 System V ABI:

    • Callee-saved registers
    • Local variables
    • Old base pointer
    • Register parameters
    • Return address
    • Stack parameters
  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));
    }