To start off, I need to write a assembly (Intel IA-32) function that returns the contents of the caller’s frame pointer. I don’t think I’m doing it correctly, but what I came up with was
pushl %ebp
movl %esp, %ebp
movl %eax, 4(ebp)
leave
ret
However, I’m supposed to use that in a c function to count the number of frames on the stack, and I’m really not sure at all how that is supposed to work. Am I supposed to jump to the value in the old ebp, and then call the function again? Any guidance would be greatly appreciated.
No, you are not required to jump anywhere, but once you have copied the frame pointer to a local variable, you can treat it as a linked list.
Perhaps it makes sense only when the distance between c and d is small.