栈帧示意图:stack pointer、frame pointer
更多参考:http://www.embeddedrelated.com/usenet/embedded/show/31646-1.php
一:
The calling convention described in this section is the one used by gcc, not the native MIPS compiler, which uses a more complex convention that is slightly faster.

Figure 6: Layout of a stack frame. The frame pointer points just below the last argument passed on the stack. The stack pointer points to the first word after the frame.
Figure 6 shows a diagram of a stack frame. A frame consists of the memory between the frame pointer ($fp), which points to the word immediately after the last argument passed on the stack, and the stack pointer ($sp), which points to the first free word on the stack. As typical of Unix systems, the stack grows down from higher memory addresses, so the frame pointer is above stack pointer.
The following steps are necessary to effect a call:
- Pass the arguments. By convention, the first four arguments are passed in registers $a0-$a3 (though simplier compilers may choose to ignore this convention and pass all arguments via the stack). The remaining arguments are pushed on the stack.
- Save the caller-saved registers. This includes registers $t0-$t9, if they contain live values at the call site.
- Execute a jal instruction.
Within the called routine, the following steps are necessary:
- Establish the stack frame by subtracting the frame size from the stack pointer.
- Save the callee-saved registers in the frame. Register $fp is always saved. Register $ra needs to be saved if the routine itself makes calls. Any of the registers $s0- $s7 that are used by the callee need to be saved.
- Establish the frame pointer by adding the stack frame size to the address in $sp.
Finally, to return from a call, a function places the returned value into $v0 and executes the following steps:
- Restore any callee-saved registers that were saved upon entry (including the frame pointer $fp).
- Pop the stack frame by adding the frame size to $sp.
- Return by jumping to the address in register $ra.
二:
Here's how I diagram the conventional PDP-11 stack layout.
| | higher addresses
+---------------+
| argN |
| ... |
| arg0 | <- FP+4
+---------------+
| link reg | <- FP+2 = SP after JSR
+===============+
| saved FP | <- FP after prologue
+---------------+
/ | locals | <- FP-2
framesize \ | ... |
+---------------+
| saved regs |
| ... | <- SP after prologue
+---------------+
| | lower addresses
Note that local function arguments are at positive offsets from FP,
local variables are at negative offsets. Also note that the frame
pointer itself is among the callee-saved registers.
See here for a survey of subroutine linkage conventions:
http://www.cs.clemson.edu/~mark/subroutines.html
http://www.cs.clemson.edu/~mark/subroutines/pdp11.html (PDP-11
specific)
and here http://cm.bell-labs.com/cm/cs/who/dmr/clcs.html (original
PDP-11 C)
栈帧示意图:stack pointer、frame pointer的更多相关文章
- Java-JVM 栈帧(Stack Frame)
一.概述 栈帧位置 JVM 执行 Java 程序时需要装载各种数据到内存中,不同的数据存放在不同的内存区中(逻辑上),这些数据内存区称作运行时数据区(Run-Time Data Areas). 其中 ...
- frame pointer及其用途
1 什么是frame pointer frame pointer指向本函数栈帧顶,通过它可以找到本函数在进程栈中的位置.有专门的寄存器保存该值. 2 frame pointer有什么用 主要是back ...
- C函数调用过程原理及函数栈帧分析(转)
在x86的计算机系统中,内存空间中的栈主要用于保存函数的参数,返回值,返回地址,本地变量等.一切的函数调用都要将不同的数据.地址压入或者弹出栈.因此,为了更好地理解函数的调用,我们需要先来看看栈是怎么 ...
- IDA Pro 权威指南学习笔记(十) - 栈帧
栈帧(stack frame)是在程序的运行时栈中分配的内存块,用于特定的函数调用 如果一个函数没有执行则不需要内存,当函数被调用时就需要用到内存 1.传给函数的参数的值需要存储到函数能够找到它们的位 ...
- 深入理解java虚拟机(十) Java 虚拟机运行时栈帧结构
运行时栈帧结构 栈帧(Stack Frame) 是用于虚拟机执行时方法调用和方法执行时的数据结构,它是虚拟栈数据区的组成元素.每一个方法从调用到方法返回都对应着一个栈帧入栈出栈的过程. 每一个栈帧在编 ...
- Java虚拟机之栈帧
写在前面的话:Java虚拟机是一门学问,是众多Java大神们的杰作,由于我个人水平有限,精力有限,不能保证所有的东西都是正确的,这里内容都是经过深思熟虑的,部分引用原著的内容,讲的已经很好了,不在累述 ...
- java 栈和栈帧
文章转载自:http://www.tuicool.com/articles/URZrMnb jvm为每个新创建的线程都分配一个堆栈.堆栈以帧为单位保存线程的状态.jvm对堆栈只进行两种操作:以帧为单位 ...
- 详细解析Java虚拟机的栈帧结构
欢迎关注微信公众号:万猫学社,每周一分享Java技术干货. 什么是栈帧? 正如大家所了解的,Java虚拟机的内存区域被划分为程序计数器.虚拟机栈.本地方法栈.堆和方法区.(什么?你还不知道,赶紧去看看 ...
- 【转载】深入理解Java虚拟机笔记---运行时栈帧结构
栈帧(Stack Frame)是用于支持虚拟机进行方法调用和方法执行的数据结构,它是虚拟机运行时数据区的虚拟机栈(Virtual Machine Stack)的栈元素.栈帧存储了方法的局部变量表,操作 ...
随机推荐
- Python-is, ==, cmp()
is 主要是判断 2 个变量是否引用的是同一个对象,如果是的话,则返回 true,否则返回 false. 判断数字相等不要用 is 操作符 1 2 3 4 5 6 7 8 9 10 11 12 > ...
- HDU 6301 (贪心+优先队列)
题目大意: 求一个长度为n的数列, 给出m个区间,这m个区间各自区间内的数不同 题解: 用优先队列来模拟过程 , 解题思路是想到了 , 可是不知道如何实现 , 果然还须继续努力呀 这道题思路是去掉重复 ...
- KD树的极简单笔记(待后续更新)
今天(18.5.4)室友A突然问我算法怎么入门,兴奋之下给他安利了邓公的<数据结构>,然而他接着又问我能不能两周内快速入门,毕竟打算搞Machine Learning,然后掏出手机看了下他 ...
- 微信小程序 template模板使用
参考文章: 微信小程序-template模板使用
- python3.6 子类的__init__调用父类的__init__
python3.6 子类的__init__调用父类的__init__ 父类 class worker: def __init__(self): self.a=1 self.b=2 if __name_ ...
- my31_MGR单写模式压测以及对比普通从库记录
场景MGR单写模式三节点,db46写节点,db47/db48为读节点工具sysbencn.压测15个小时,db46上18线程纯写,12线程oltp混合测试,db48上12线程select在压测2个小时 ...
- 邮件email
参考地址:https://blog.csdn.net/baidu_30000217/article/details/52942258 邮箱配置地址:http://service.exmail.qq.c ...
- myeclipse更改后台代码不用重启tomcat的方法
myeclipse更改后台代码不用重启tomcat的方法 方法1:在WebRoot下的META-INF文件夹中新建一个名为context.xml文件,里面添加如下内容(要区分大小写): <C ...
- Python基本数据类型和其常用方法
Number Bool String List Tuple Dictionary Number 在Python3中 所有整数不管多大都是Int类型,没有Long类型,Python2中有Long类型. ...
- TOJ 1717 WOJ
描述 Alex likes solving problems on WOJ (http://acm.whu.edu.cn/oak). As we all know, a beautiful ballo ...