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

边栏推荐
猜你喜欢

Erreur Keil de Huada Single Chip Computer La solution de Weak

SQL Server - Window Function - 解决连续N条记录过滤问题

数智化进入“深水区”,数据治理是关键

蓄力中台,用友iuap筑牢社会级企业数智化新底座

binder hwbinder vndbinder

binder hwbinder vndbinder

连接集成开发专题月 | 企业主数据治理的驱动因素

【debug】平台工程接口调试

华大单片机KEIL添加ST-LINK解决方法

Running lantern experiment based on stm32f103zet6 library function
随机推荐
网络传输是怎么工作的 -- 详解 OSI 模型
什么是SSR/SSG/ISR?如何在AWS上托管它们?
华大单片机KEIL报错_WEAK的解决方案
Implementation of reliable distributed locks redlock and redisson
UE4-Actor基础知识
(LC)46. Full Permutation
Doctoral Dissertation of the University of Toronto - training efficiency and robustness in deep learning
Array exercises follow up
1030 Travel Plan
1028 List Sorting
429- binary tree (108. convert the ordered array into a binary search tree, 538. convert the binary search tree into an accumulation tree, 106. construct a binary tree from the middle order and post o
ABAP随笔-通过api获取新冠数据
On thread safety
PyCharm常用功能 - 断点调试
基于STM32F103ZET6库函数外部中断实验
(LC)46. 全排列
Redis cluster Series III
字典树(复习)
驾驭一切的垃圾收集器 -- G1
308. 二维区域和检索 - 可变 线段树/哈希