当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Feign请求日志统一打印
[untitled]
【UDS统一诊断服务】一、诊断概述(3)— ISO 15765体系结构
Robocode教程7——雷达锁定
[leetcode 401] binary Watch
Qthread simple test understanding
xlsxwriter.exceptions.FileCreateError: [Errno 13] Permission denied问题
Rust:在线程池中共享变量
Animation - Introduction to keyframes
队列解决约瑟夫问题
爬虫之requests基本用法
解决ArcGIS分区统计显示太多唯一值执行失败
scikit-learn sklearn 0.18 官方文档中文版
grub boot. S code analysis
【UDS统一诊断服务】四、诊断典型服务(6)— 输入输出控制单元(0x2F)
Solution to the trial of ycu Blue Bridge Cup programming competition in 2021
[leetcode 54] spiral matrix
[leetcode 954] double pair array
How SYSTEMd uses / etc / init D script
ArcGIS表转EXCEL超出上限转换失败