CS520
Spring 2014
Laboratory 7
Monday March 17
The lab must be submitted prior to 8am on Tuesday March 18.
The goal of this lab is to write a simple Intel 64 assembly
language function and learn how to call this from C code.
Before starting this lab, review the
lecture
on The Intel 64 Architecture,
particularly the discussion of slide 8 in the
slides
for the lecture.
- Write an Intel 64 assembly language function,
called getFP, to return
the caller's frame pointer, i.e. the contents of the %rbp
register.
This function takes no arguments and needs to be callable from C code.
Place this function in a file called asm.s.
From the C code point of view this function returns either a
long or some kind of pointer type.
That is, this function returns a 64-bit value.
- 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 %rbp 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.
- 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 lab7.c.
- 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.
The getFP function will be worth 20 points and the
frameCount function will be worth 30 points.
Please turn-off any debugging code before you submit your lab.
Submit the code you wrote for steps 1 and 3 via:
~cs520/bin/submit lab7 lab7.c asm.s
Submissions can be checked by typing:
~cs520/bin/scheck lab7
Last modified on March 13, 2014.
Comments and questions should be directed to
hatcher@unh.edu