什么叫栈帧?
就是函数的调用环境。bp和sp中间那一段就是函数调用环境。

在AT&T环境下栈帧是有点不一样的:
1、叶子函数不会开辟空间(即减rsp)给局部变量。



叶子函数:sp往上走128个字节都是他的区域"red zone"红色区域,受保护的。
2、非叶子函数才会开辟空间。


3、总结
为什么叶子函数不用做sp减的操作,来开辟一段受保护的空间?
——因为叶子函数,能保证不会再调用别的函数,能保证堆栈不会被其他函数破坏。所以可以随便往里面放东西。所以sp减不减都可以放东西。可叶子函数的sp为什么不上去呢?
——为性能考虑。

上部分叶子函数sp不减;下部分非叶子函数sp减,减了后最后面还要加回去。所以sp不减性能上有优势,减少了两条指令
。
不要小看只少了这两条指令,有些函数调用非常频繁,时时刻刻都在调用,少两条指令,也能带来性能上很大的提升。
4、混编
4.1 单独汇编文件

4.2 嵌入汇编代码(内联汇编)

嵌入汇编,实际开发中没必要这么干。只是为了看懂有些框架里面嵌入了汇编。
5、AT&T和arm汇编不一样的地方只是在于寄存器和指令的名称,其他都差不多,暂时不去碰arm汇编,因为要设计到很多东西。
网友评论