CS520
Spring 2012
Laboratory 9
Friday April 6
The lab must be submitted prior to 8am on Saturday April 7.


The goal of this lab is to write a simple Intel IA-32 assembly language function and learn how to call this from C code.

  1. Write an Intel IA-32 assembly language function, called getFP, to return the caller's frame pointer, i.e. the contents of the %ebp register. This function takes no arguments and needs to be callable from C code. Place this function in a file called lab9-asm.s.

  2. Test the function by calling it from the main function of a C program and explore the stack frames of main and the caller of main. What is in the old %ebp slot of the last frame on the stack? Look for some way to be able to identify the last frame on the stack. Keep this C code in a separate file from the function because you will not be submitting this code that you used for testing.

  3. Write a C function, called frameCount, that takes no arguments and uses the assembly language function of step 1 to count and return the number of stack frames that there are on the stack at the time the function is called. This count should not include the function performing the count. The count should include main but not the caller of main. Place this function in a file called lab9.c.

  4. Test your C function by calling it from other C code, with a variety of number of frames on the stack when you call the function. Keep this C code in a separate file from the function because you will not be submitting this code that you used for testing.

    Please turn-off any debugging code before you submit your lab.

  5. Submit the code you wrote for steps 1 and 3 via:
    ~cs520/bin/submit lab9 lab9.c lab9-asm.s

  6. Submissions can be checked by typing:
    ~cs520/bin/scheck lab9


Last modified on April 5, 2012.

Comments and questions should be directed to hatcher@unh.edu