惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - InterMa

离开了。。。 安装ubuntu6.06的一个应注意之处 - InterMa - 博客园 今天和同学们包饺子啦~ - InterMa - 博客园 。。。。。。 关于ODR和Template 第3方client连接talk.google.com的一些注意之处 王国维 之 三境界 Castle ActiveRecord中ntext类型的映射 给俱乐部中的朋友们问个好~ :-) 使用Castle ActiveRecord的几点小经验 拳脚小功夫,容人大丈夫 No Touch Required 一些页面配色的资源【存档自用】 Vim7下配置C/C++的Omni complete Vim7下配置Python的Omni complete Richard Stallman和自由软件运动 扯2,3事 写了一个Google登陆风格的table 最近正在FPS。。。
函数调用与堆栈清理
InterMa · 2006-11-08 · via 博客园 - InterMa

今天看了一会《Professional Assembly Language》,在P104函数调用的地方,看到了一些好东东,摘抄如下:
(如果你不了解函数调用与堆栈清理的基础概念,详见:http://www.turbozv.com/read.php?78 ,赶快补补)

首先是一个函数的模版,它自己(被调用方)清理堆栈(这个就是__stdcall了):

function_label:
    pushl 
%ebp
    movl 
%esp, %ebp
    # your code goes here
    movl 
%ebp, %esp
    popl 
%ebp
    ret

还用注意call function_label的时候首先将%eip入栈,然后ret的时候恢复saved %eip => %eip。

如果是调用C的库函数,例如:printf(),那就要调用方清理堆栈了(__cdecl):

.section .data
output:
    .asciz 
"This is section %d\n"

.section .text

    pushl $

1
    pushl $output
    call printf
    add $
8%esp # clear up stack

顺便补2个常见的Asm操作:
【1】为auto变量分配空间:
直接操作%esp就可以了,例如:subl $24, %esp #分配24个字节。
访问局部变量的时候,直接使用%ebp+偏移就可以了。
【2】地址对齐:
andl $-16, %esp #按16地址对齐。