当前位置:网站首页>函数栈帧的创建和销毁
函数栈帧的创建和销毁
2022-07-25 21:24:00 【风起、风落】
文章目录
一、对于esp与ebp寄存器的说明
ebp esp两个寄存器 存放的是地址
使用地址维护函数栈帧
二、对于创建和销毁的全过程
1.对于_mainCRTstarup的函数的创建

注意事项:
压栈 (push):给栈顶放一个元素
出栈(pop):在栈顶删除一个元素
栈空间的地址使用为先使用高地址,在使用低地址
- push 压栈操作 将ebp压入栈中
同时 esp指向, ebp往上地址变小, 所以 esp的地址变小了

- mov: 将esp的值给ebp
两者指向同一个位置
- sub (减 )
将esp减去0E4h(八进制)
(1)
(2)esp由于地址变小 向上去 而esp 与ebp两者围成的空间正好是main函数的栈帧
- push 在main函数栈顶压入 ebx esi edi
随着压入数据 esp也随之指向数据 即esp向上移
2.对于main函数的创建
lea 代表load effective address 加载有效地址
将ebp-0E4h放在 edi中
dowrd充当4个字节
从edi位置开始的 ecx(存放39h次) 的dword数据全部改成0xCCCCCCCCh一直到ebp结束
(1).为什么有时候会打印出烫烫烫
0Ah代表10
把0Ah放到ebp-8的数据中
因为都是地址 所以ebp-8为在ebp地址减去8个字节
如果a中没有被赋值 则放入为0xCCCCCCCCh
所以有时候打印结果为烫烫烫烫烫烫
14h以十六进制打印 代表20 即ebp-20
ebp-20h代表ebp-32
ebp-20 为b的值 即20
把ebp-14h(ebp-20)传入eax中
push eax 将eax压栈
同时esp指向eax
2.
将ebp-8传入ecx中
同时将ecx 压栈
此时ebp-8存放的是a 值为10
esp指向ecx
3.
调用一个函数
将下一条指令的地址压栈
同时esp指向call下一条指令的地址
3.对于Add的函数的创建

将ebp压栈 esp指向ebp 这里是主函数里的ebp
.将esp赋值给ebp,ebp与esp都指向ebp
2.
sub: 将esp减去0CCh
因为地址小的在上
push 压栈 ebx esi edi
3.
从edi位置开始 进行ecx(33h十六进制)次dword数据 全部转化成0CCCCCCCCh
4.
把0放在ebp-8的位置上
(2).为什么说形参不在函数中

(3).函数中return值如何放回的
>

1.
出栈 此时esp地址变大 向下移
mov 把ebp赋值给esp
(4).ebp-main出栈后ebp寄存器的指向情况
(5).形参a,b如何返回操作系统
返回ret是返回到 call下一条指令的地址
这里随着add函数的销毁 esp也从下一条指令的地址位置弹出到下一个位置
将原来esp所指的地址加8 即现在的位置
就会将形参 a b 还给操作系统

把eax移动到 ebp-32(20h为16进制)中
即将 函数z的值 传递到主函数的c中
4.整体过程图解
边栏推荐
- Temperature and humidity environment monitoring system based on stm32
- Add startup software items when the win system starts up
- DDD的Go实战
- Interface testing tool restlet client
- Research: more than 70% of doctors are still prescribing unsafe antibiotic drugs
- Qixin Jushi cloud spectrum new chapter | Haitai Fangyuan and Sichuan Unicom reach ecological strategic cooperation
- [technical dry goods] how to ensure the idempotency of the interface?
- [online tutorial] iptables official tutorial -- learning notes 2
- Cesium polygon gradient texture (canvas)
- 一道golang中关于接口和实现的面试题
猜你喜欢

Pychart automatically enters the test mode when running the program

Qixin Jushi cloud spectrum new chapter | Haitai Fangyuan and Sichuan Unicom reach ecological strategic cooperation

Detailed explanation of JVM memory model and structure (five model diagrams)

ONEFLOW V0.8.0 officially released

Cesium polygon gradient texture (canvas)

Too many passwords, don't know how to record? Why don't you write a password box applet yourself
![[fiddlertx plug-in] use Fiddler to capture the package Tencent classroom video download (unable to capture the package solution)](/img/de/7a288ee8e6001235d4869c10503932.png)
[fiddlertx plug-in] use Fiddler to capture the package Tencent classroom video download (unable to capture the package solution)

NVIDIA has opened source a comprehensive library of 3D deep learning based on pytorch

零基础学习CANoe Panel(17)—— Panel CAPL Function

Advanced technology management - how can the team be broken?
随机推荐
LeetCode刷题——猜数字大小II#375#Medium
As a test, how to understand thread synchronization and asynchrony
Vivo official website app full model UI adaptation scheme
NPM module removal_ [solved] after NPM uninstalls the module, the module is not removed from package.json [easy to understand]
【网络教程】IPtables官方教程--学习笔记2
mysql8.0 mha实现高可用《mha》
When MySQL resets the root password and modifies the password, an error occurs. The password field does not exist
Trusted and controllable way of Tencent cloud database
Kali modify the update source (it is not safe to update with this source)
What's special about Huawei's innovative solutions to consolidate the foundation of ERP for small and medium-sized enterprises?
全志芯片bsp命名规则
Fusing and degrading Sentinel
数据库sql语句练习题「建议收藏」
Byte side: can TCP and UDP use the same port?
Based on pexels image material API, sort out the material resource library
JMeter distributed pressure measurement
ONEFLOW V0.8.0 officially released
Niuke-top101-bm37
All non isomorphic subgraphs of a directed complete graph of order 3 (number of different hook graphs)
PayPal PHP product trial period "recommended collection"

































