当前位置:网站首页>Call procedure of function
Call procedure of function
2022-04-23 06:36:00 【*Flowers bloom on the street】
One 、 Concept
register :CPU The variables in the
cpu There are many registers in the , Register for access
The process of function call will generate a stack ,
esp: Top register
ebp: Bottom of stack register
Two 、 Function call procedure
1. Parameter stack
Parameter stack :(c Language )
Four byte stack :
#include<stdio.h>
int fun(int a, int b)
{
int c = 0;
return c = a + b;
}
int main()
{
int a = 10;
int b = 5;
int c = fun(a,b);
printf("%d", c);
return 0;
}
fun(a,b)
4 Byte parameter stack ( The order : From right to left )
fun(a,b); First b Again a
The way : Using registers push Into the
Eight character section into the stack :
#include<stdio.h>
struct Node
{
int _1;
int _2;
};
int fun(struct Node a, struct Node b)
{
int c = 20;
return c;
}
int main()
{
struct Node a = { 10,20 };
struct Node b = { 30,40 };
fun(a, b);
return 0;
}
8 Byte parameter stack :
The order : From right to left
The way Using registers push Into the
12 Byte parameter stack
12 byte ( Greater than 8 byte ) Parameter stack :
The order : From right to left
The way : First, open up enough space for this parameter at the top of the stack , Then copy the data in
c++ Parameters in the stack
c++ As long as it is a custom type , No matter how many bytes , All adopt the method of opening up space first , The way of assignment after
2. Function stack frame
Put the instruction address of the next line of the caller's function on the stack
Put the bottom register of the caller's function on the stack
Give Way ebp = esp
Give Way esp = esp -***
Stack other used registers ,
Write all the newly opened stack frame space as cccc cccc
3. Function return value
c In language
4 Byte return value
The way : Put the return value into the register and bring it back to
8 Byte return value
The way : Put the return value in two registers , Bring back
12 byte ( Greater than 8 byte ) Return value
The way :
After the function parameters are stacked , Stack the address on a caller's stack frame ( Near the top of the stack )
When the return value returns , Write the return data to the caller's address that was previously stacked
After returning , The data will be taken from this address
c++ in
Byte return value mode :
The custom types are based on the stack caller address
4. Function stack exit
Check the current function stack frame
Take the thread protected register out of the stack
Give Way esp=ebp
ebp= pop
Restore the address of the next instruction line
Remove parameters
notes : The function call procedure in this paper depends on c Language default calling convention _cdecl
There are other calling methods , Such as :_stdcall , _fastcall
版权声明
本文为[*Flowers bloom on the street]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230547207441.html
边栏推荐
猜你喜欢
【UDS统一诊断服务】三、应用层协议(1)
[leetcode 54] spiral matrix
Programmers can also write novels
大学概率论与数理统计知识点详细整理
Explanation of the second I interval of 2020 Niuke summer multi school training camp
Swagger2 generates API documents
类和对象的初始化(构造函数与析构函数)
Export the articles written in CSDN to PDF format
clion安装教程
Basemap库绘制地图
随机推荐
Explanation of the second I interval of 2020 Niuke summer multi school training camp
【UDS统一诊断服务】四、诊断典型服务(2)— 数据传输功能单元
C语言循环结构程序
GNU EFI header file
多线程爬取马可波罗网供应商数据
Rust 中的指针:Box、Rc、Cell、RefCell
Feign请求日志统一打印
[leetcode217] there are duplicate elements
安装pyshp库
GDB debugger installation and use
Vscode custom comments
Import of data
Basic knowledge of network in cloud computing
Graduation project, viewing screenshots of epidemic psychological counseling system
SQL -- data filtering and grouping
The most practical chrome plug-in
日志
爬虫效率提升方法
从源代码到可执行文件的过程
SQL sorts according to the specified content