当前位置:网站首页>从指令交读掌握函数调用堆栈详细过程
从指令交读掌握函数调用堆栈详细过程
2022-06-27 18:05:00 【无敌的神龙战士】
int sum(int a, int b)
{
int temp = 0;
temp = a + b;
return temp;
}
int main()
{
int a = 10; //
int b = 20;
int ret = sum(a, b);
cout << ret << endl;
}
1 mian函数调用sum,sum执行完以后,怎么知道回到那个函数?
2 sum函数执行完,回到main以后,怎么知道从哪一行指令继续执行呢 ?

- ESP:存储的是当前函数栈帧栈顶的地址
- EBP:存储的是main函数栈底的地址
int a = 10 => mov dword ptr[a], 0Ah 或者 mov dword ptr[ebp - 4], 0Ah
int b = 20; => mov dword ptr[ebp - 8], 14h

sum(a, b)
= >
mov eax, dword ptr[ebp-8]
push eax // b
mov eax, dword ptr[ebp-4]
push eax //a

int ret = sum(a, b)
call sum
add esp, 8 // 地址为0x08124458
mov dword ptr[ebh - 0Ch], eax

int sum(int a, int b)
{ // push ebp
mov ebp, esp
sub esp, 4Ch
int temp = 0; mov dword ptr[ebp - 4] 0
temp = a + b; mov eax, dword ptr[ebp + 0Ch] a + b mov dword ptr[ebp - 4], eax
return temp; mov eax, dword ptr[ebp - 4]
}// mov esp, ebp
pop ebp

ret // 出栈操作 把出栈的内容放入CPU的PC寄存器里面

边栏推荐
猜你喜欢
随机推荐
实战回忆录:从Webshell开始突破边界
【help】JVM的CPU资源占用过高问题的排查
MySQL表的增删改查(基础)
【登录界面】
经纬度分析
Determine whether a variable is an array or an object?
UE4:Build Configuration和Config的解释
Implementation of reliable distributed locks redlock and redisson
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
多伦多大学博士论文 | 深度学习中的训练效率和鲁棒性
binder hwbinder vndbinder
labelimg使用指南
Pyhton爬取百度文库文字写入word文档
External interrupt experiment based on stm32f103zet6 library function
Is it safe to buy stocks and open an account on the account opening link of the securities manager? Ask the great God for help
嵌入式软件开发中必备软件工具
中金证券经理给的开户二维码安全吗?找谁可以开户啊?
Function key input experiment based on stm32f103zet6 Library
NVIDIA Clara-AGX-Developer-Kit installation
使用logrotate对宝塔的网站日志进行自动切割








