C language - function stack frame (each time a function is called, the general process of developing the function)

Idea:

  1. emm, I'm a little confused. I only know a rough idea about this. If I dig deeper later, I'll go back and add more.
  2. above picture
  3. The position of the brackets is the function stack frame generated every time a function is created and called. It can also be understood as a space opened up in the computer every time a function is called.
  4. This space is actually a stack, with the bottom pointer of the ebp stack and the top pointer of the esp stack. They just draw a frame and draw an area. Then ebs, edi, and ebi are the three initialization stacks, from edi to ebp. The content in the area is refreshed to CCCCCC, which is commonly referred to as garbled code.
  5. After these tasks are completed, the creation of the internal variable space of the function begins. In this figure, the bottom is the high address, and the bottom is the low address. Each compiler is different, so the division blocks are also different. Use ebp-8, which is the bottom The high address, minus 8 bytes, is the starting address of this variable space.
  6. When the function is running, the data is obtained downwards, that is, under the function area. This can explain why, when recursing, the value of each recursion is different, because after each recursion, the new recursion value will be A space is created, then pushed to the top of the stack, and then the next recursive function is created.
  7. And every time you enter recursion, it is a brand new space. What this space does does not do anything in other function spaces. They do not interfere with each other, unless you want the final return value, what value do you want to get from the inside, and what is the final return value? time, bring it back.

 

Guess you like

Origin blog.csdn.net/m0_59844149/article/details/131481148