Call stack Structure
The stack frame at the top of the stack is for the currently executing routine. The stack frame usually includes at least the following items (in push order):
- the arguments (parameter values) passed to the routine (if any);
- the return address back to the routine's caller (e.g. in the DrawLinestack frame, an address intoDrawSquare's code); and
- space for the local variables of the routine (if any).

Call stack layout
Stack and frame pointers[edit]
When stack frame sizes can differ, such as between different functions or between invocations of a particular function, popping a frame off the stack does not constitute a fixed decrement of the stack pointer. At function return, the stack pointer is instead restored to the frame pointer, the value of the stack pointer just before the function was called. Each stack frame contains a stack pointer to the top of the frame immediately below. The stack pointer is a mutable register shared between all invocations. A frame pointer of a given invocation of a function is a copy of the stack pointer as it was before the function was invoked.[2]
The locations of all other fields in the frame can be defined relative either to the top of the frame, as negative offsets of the stack pointer, or relative to the top of the frame below, as positive offsets of the frame pointer. The location of the frame pointer itself must inherently be defined as a negative offset of the stack pointer.
Storing the address to the caller's frame[edit]
In most systems a stack frame has a field to contain the previous value of the frame pointer register, the value it had while the caller was executing. For example, the stack frame of DrawLine would have a memory location holding the frame pointer value that DrawSquare uses (not shown in the diagram above). The value is saved upon entry to the subroutine and restored upon return. Having such a field in a known location in the stack frame enables code to access each frame successively underneath the currently executing routine's frame, and also allows the routine to easily restore the frame pointer to the caller's frame, just before it returns.
Lexically nested routines[edit]
Programming languages that support nested subroutines also have a field in the call frame that points to the stack frame of the latest activation of the procedure that most closely encapsulates the callee, i.e. the immediate scope of the callee. This is called an access link or static link (as it keeps track of static nesting during dynamic and recursive calls) and provides the routine (as well as any other routines it may invoke) access to the local data of its encapsulating routines at every nesting level. Some architectures, compilers, or optimization cases store one link for each enclosing level (not just the immediately enclosing), so that deeply nested routines that access shallow data do not have to traverse several links; this strategy is often called a "display".[3]
Access links can be optimized away when an inner function does not access any (non-constant) local data in the encapsulation, as is the case with pure functions communicating only via arguments and return values, for example. Some historical computers, such as the Burroughs large systems, had special "display registers" to support nested functions, while compilers for most modern machines (such as the ubiquitous x86) simply reserve a few words on the stack for the pointers, as needed.
Overlap[edit]
For some purposes, the stack frame of a subroutine and that of its caller can be considered to overlap, the overlap consisting of the area where the parameters are passed from the caller to the callee. In some environments, the caller pushes each argument onto the stack, thus extending its stack frame, then invokes the callee. In other environments, the caller has a preallocated area at the top of its stack frame to hold the arguments it supplies to other subroutines it calls. This area is sometimes termed the outgoing arguments area or callout area. Under this approach, the size of the area is calculated by the compiler to be the largest needed by any called subroutine.
Call stack Structure的更多相关文章
- 线性数据结构之栈——Stack
		Linear data structures linear structures can be thought of as having two ends, whose items are order ... 
- 【LeetCode OJ】Evaluate Reverse Polish Notation
		Problem link: http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/ According to the wik ... 
- MakeObjectInstance的前世今生(关键是ECX的何时入栈以及Self指针何时存储的)
		高手们的文章有很大启发,但是总有些小错,也有没交代清楚的,以下是我的理解: 编译器编译MainWndProc的时候,它是一个正常Delphi普通函数,MakeObjectInstance对它做变换是运 ... 
- java建立二叉树,递归/非递归先序遍历,递归/非递归中序遍历,层次遍历
		import java.util.LinkedList; import java.util.Scanner; import java.util.Stack; //structure of binary ... 
- [转] iOS ABI Function Call Guide
		source: apple ARMv6 Function Calling Conventions When functions (routines) call other functions (sub ... 
- iOS - Block底层解析
		Block是iOS开发中一种比较特殊的数据结构,它可以保存一段代码,在合适的地方再调用,具有语法简介.回调方便.编程思路清晰.执行效率高等优点,受到众多猿猿的喜爱.但是Block在使用过程中,如果对B ... 
- allego 输出报告说明
		List of Available Reports Assigned Function Report Lists all assigned functions, sorted by function ... 
- SECD machine
		SECD machine 对程序语言理论的理解 程序语言理论主要研究语法.语义及语言的实现.编程语言有语法,各种数学逻辑.结构化数据都有语法.乔姆斯基的语言体系及巴科斯范式是语法分析的基础,语法分析将 ... 
- 【deep learning精华部分】稀疏自编码提取高阶特征、多层微调完全解释及代码逐行详解
		我们前面已经讲了如何训练稀疏自编码神经网络,当我们训练好这个神经网络后,当有新的样本输入到这个训练好的稀疏自编码器中后,那么隐藏层各单元的激活值组成的向量就可以代表(因为根据稀疏自编码,我们可以用来恢 ... 
随机推荐
- hdu oj 3127 WHUgirls(2009 Asia Wuhan Regional Contest Online)
			WHUgirls Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total ... 
- Binary Tree Maximum Path Sum  自底向上求解(重重重重)
			题目: 链接 解答: 自底向上求解.left_max right_max分别返回了左右子树的最大路径和,假设左右子树最大路径和小于0.那么返回零. 用这个最大路径和和根节点的值相加.来更新最大值,同一 ... 
- 华为OJ1964-求解立方根(牛顿迭代法)
			一.题目描述 描述: 计算一个数字的立方根,不使用库函数. 函数原型double getCubeRoot(double input) 输入: 待求解参数 double类型 输出: 输出参数的立方根,保 ... 
- 告诉大家我是如何在14:00秒杀到 《深入理解Bootstrap》
			1.打开火狐,不用IE,3个评论窗口,层叠在一起,可以点击3次哦. 2.打开一个百度的现在时间,不能看你本机的时间,要互联网的时间. 3.等时间到13:59:59,开始依次点击按钮,总有你预想不到的结 ... 
- easyUI datagrid 时间格式化
			从后台传过来的数据,其中含有日期字段,那么在前端的easyUI这里显示的话,会显得比较怪异,一大串,中间是个T,后面一大堆零,不知道是什么意思. 看来要进行格式化. 问题是,在哪里格式化? 如果在后端 ... 
- go4--break,continue + 标签
			package main /* 指针 Go虽然保留了指针,但与其它编程语言不同的是,在Go当中不 支持指针运算以及”->”运算符,而直接采用”.”选择符来操作指针 目标对象的成员 操作符”&am ... 
- Android 通过USB查看kernel调试信息【转】
			本文转载自:http://blog.csdn.net/lindonghai/article/details/51683644 前提:电脑已安装adb并可正常使用. 在调试Android驱动时,需要查看 ... 
- InfluxDB存储引擎Time Structured Merge Tree——本质上和LSM无异,只是结合了列存储压缩,其中引入fb的float压缩,字串字典压缩等
			The New InfluxDB Storage Engine: Time Structured Merge Tree by Paul Dix | Oct 7, 2015 | InfluxDB | 0 ... 
- 打印二叉树中距离根节点为k的所有节点
			package tree; public class Printnodesatkdistancefromroot { /** * Given a root of a tree, and an inte ... 
- 排名Top 100的Java类库
			和去年一样,排名第一的类库,依旧是JUnit.基于它扩展的 JUnit Runner 占据第二名的位置,甚至是较旧的 junit.framework 此次也在第三名的位置.也就是说JUnit包揽了前三 ... 
