Stack and Invoke conventions

Source: Internet
Author: User

The stack is defined as a special container that the user can press into the stack, or eject the data in the stack, and follow the advanced post-out (FILO) principle. In a computer system, a stack is a dynamic memory area with the above properties. The program can either press the data into the stack or eject the data from the top of the stack.

In the classic operating system, the stack from high address to low address growth, under I386, the top of the stack by the ESP register to locate. The stack top address is reduced, and the top address of the stack is increased by ejecting.

Stack plays an important role in the process of program operation. The stack holds the information that a function call needs to maintain, which is often referred to as a stack frame or activity record. Generally include the following aspects:

  • The return address and parameters of the function.
  • Temporary variables: include non-static local variables for the function and other temporary variables that the compiler automatically generates.
  • Saved context: Includes registers that need to remain unchanged before and after a function call.

A common activity record is as follows:

The activity record for a function is scoped by the EBP and ESP two registers. The ESP register always points to the top of the stack, and it points to the top of the active record of the current function. The EBP register points to a fixed position of the function's active record, called the frame pointer. A fixed ebp can be used to locate individual data in a function's activity record. For example, the address of the function return address is ebp+4, and then forward is pressed into the stack of parameters, the address is ebp+8,ebp+12, depending on the number and size of parameters. The value directly pointed to by EBP is the value of EBP before the function is called, so that when the function returns, EBP can revert to the value before the call by reading this value.

The procedure for a function call under I386:

  • Press all or part of the parameters into the stack, and if there are other parameters that are not in the stack, use some specific registers to pass.
  • Press the address of the next instruction in the current instruction into the stack.
  • Jumps to the function body execution.
  • Push EBP.
  • mov ebp,esp:esp=ebp.
  • "Optional" sub esp,xxx: In

Stack and Invoke conventions

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.