Stack and stack frame (2)

Source: Internet
Author: User
Tags benchmark

Stack frame

Stack frames are a space allocated for a specific process in the stack. Each process generates a stack frame. The stack frame is determined by two registers: The frame pointer EBP and the stack pointer ESP. For a stack frame, the frame pointer EBP is fixed. Therefore, the frame pointer can be used as the benchmark pointer in a stack frame. Other storage contents can be used as the benchmark to determine the relative position. The stack pointer ESP always points to the top of the stack. StillArticleThe example of the P function calling Q function in is background. First, there will be a p-process stack frame in the stack. When the Q-process is called in the p-process, it will introduce registers, return addresses, and so on to the stack described in the previous article, then create stack frames for the Q process. The process of setting up stack frames is actually to open up space. When the P registers and return addresses are all written into the stack, we also need to import EBP into the stack. I understand that it is to import the EBP of caller P into the stack, because the caller P is not over, if p is to continue executing after the Q function is over, it should still use its stack frame pointer as the reference address. If it is not saved, during the creation of Q stack frames, EBP will be assigned a new value to overwrite the value of P's frame pointer. After all the above data is saved in the stack, the ESP value is assigned to the EBP so that a new stack frame is created. Because the new ESP pointer is pushed down (because the inbound stack is pushed in the direction of the small address), the new stack frame has its own storage space. A complete stack frame is created.

 

Because you cannot upload images today, you cannot take out instances. I feel that I do not understand this concept enough. I should be studying it.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.