当前位置:网站首页>Grasp the detailed procedure of function call stack from instruction reading
Grasp the detailed procedure of function call stack from instruction reading
2022-06-27 20:02:00 【Invincible Dragon Warrior】
List of articles
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 Function call sum,sum After execution , How do you know to go back to that function ?
2 sum Function execution finished , go back to main in the future , How do you know which line of instruction to continue execution from ?

- ESP: It stores the address of the top of the current function stack frame
- EBP: What's stored is main The address at the bottom of the function stack
int a = 10 => mov dword ptr[a], 0Ah perhaps 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 // The address is 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 // The stack, Put the contents of the stack into CPU Of PC In the register

边栏推荐
- ABAP随笔-通过api获取新冠数据
- 作用域-Number和String的常用Api(方法)
- Redis持久化
- ABAP essays - interview memories hope that everyone's demand will not increase and the number of people will soar
- 本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
- Hanoi Tower problem
- database engine
- UE4:Build Configuration和Config的解释
- 蓄力中台,用友iuap筑牢社会级企业数智化新底座
- Is it safe to buy stocks online and open an account?
猜你喜欢

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

微信iOS版8.0.24更新发布 缓存细分清理上线

键入网址到网页显示,期间发生了什么?
![[bug] Lenovo Xiaoxin has a problem. Your pin is unavailable.](/img/2a/da8e998cb4e89d655f3c4116316925.png)
[bug] Lenovo Xiaoxin has a problem. Your pin is unavailable.

Embracing cloud Nativity: Practice of Jiangsu Mobile order center

数组练习 后续补充

DCC888 :Register Allocation

Crontab's learning essays

Wechat IOS version 8.0.24 update release cache subdivision cleaning Online

The Fifth Discipline: the art and practice of learning organization
随机推荐
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
ABAP-CL_OBJECT_COLLECTION工具类
Is the account opening QR code given by CICC securities manager safe? Who can I open an account with?
数据库索引
海底电缆探测技术总结
SQL报了一个不常见的错误,让新来的实习生懵了
聊聊毕业季
Manage rust project through cargo
Database lock problem
Hanoi塔问题
UE4 realizes long press function
redis集群系列二
Rust 所有权进阶 -- 内存管理
经纬度分析
Rust advanced ownership - memory management
[debug] platform engineering interface debugging
Redis cluster Series II
微信iOS版8.0.24更新发布 缓存细分清理上线
1023 Have Fun with Numbers
308. 二维区域和检索 - 可变 线段树/哈希