简体   繁体   中英

Counting number of frames on stack

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 ac 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.

 int mymagicfunction(int a, int b){

     int *c = asm_copy_ebp();
     int *d = c;
     while ( it_makes_sense ) {
           c=*c;
           dump_memory_between(c,d);
           d=c;
     }

Perhaps it makes sense only when the distance between c and d is small.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM