当前位置:网站首页>从指令交读掌握函数调用堆栈详细过程
从指令交读掌握函数调用堆栈详细过程
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寄存器里面

边栏推荐
猜你喜欢
随机推荐
labelimg使用指南
MASS幸运哈希游戏系统开发丨冲突解决方法(代码分析)
可靠的分布式锁 RedLock 与 redisson 的实现
Buzzer experiment based on stm32f103zet6 library function
Cdga | what is the core of digital transformation in the transportation industry?
binder hwbinder vndbinder
shell脚本常用命令(三)
CMS 执行的七个阶段
散列表(Hash)-复习
聊聊毕业季
# Leetcode 821. 字符的最短距离(简单)
什么是SSR/SSG/ISR?如何在AWS上托管它们?
crontab的学习随笔
NVIDIA Clara-AGX-Developer-Kit installation
谈谈线程安全
金鱼哥RHCA回忆录:DO447管理项目和开展作业--创建作业模板并启动作业
Rust 所有权进阶 -- 内存管理
PyCharm常用功能 - 断点调试
这个是和数据采集一样,可以定义一个参数为上个月或者前一天,然后在sql中使用这个参数吗?
One week technical update express of substrate and Boca 20220425 - 20220501







