更多参考: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:

  1. 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.
  2. Save the caller-saved registers. This includes registers $t0-$t9, if they contain live values at the call site.
  3. Execute a jal instruction.

Within the called routine, the following steps are necessary:

  1. Establish the stack frame by subtracting the frame size from the stack pointer.
  2. 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.
  3. 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:

  1. Restore any callee-saved registers that were saved upon entry (including the frame pointer $fp).
  2. Pop the stack frame by adding the frame size to $sp.
  3. 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的更多相关文章

  1. Java-JVM 栈帧(Stack Frame)

    一.概述 栈帧位置 JVM 执行 Java 程序时需要装载各种数据到内存中,不同的数据存放在不同的内存区中(逻辑上),这些数据内存区称作运行时数据区(Run-Time Data Areas). 其中 ...

  2. frame pointer及其用途

    1 什么是frame pointer frame pointer指向本函数栈帧顶,通过它可以找到本函数在进程栈中的位置.有专门的寄存器保存该值. 2 frame pointer有什么用 主要是back ...

  3. C函数调用过程原理及函数栈帧分析(转)

    在x86的计算机系统中,内存空间中的栈主要用于保存函数的参数,返回值,返回地址,本地变量等.一切的函数调用都要将不同的数据.地址压入或者弹出栈.因此,为了更好地理解函数的调用,我们需要先来看看栈是怎么 ...

  4. IDA Pro 权威指南学习笔记(十) - 栈帧

    栈帧(stack frame)是在程序的运行时栈中分配的内存块,用于特定的函数调用 如果一个函数没有执行则不需要内存,当函数被调用时就需要用到内存 1.传给函数的参数的值需要存储到函数能够找到它们的位 ...

  5. 深入理解java虚拟机(十) Java 虚拟机运行时栈帧结构

    运行时栈帧结构 栈帧(Stack Frame) 是用于虚拟机执行时方法调用和方法执行时的数据结构,它是虚拟栈数据区的组成元素.每一个方法从调用到方法返回都对应着一个栈帧入栈出栈的过程. 每一个栈帧在编 ...

  6. Java虚拟机之栈帧

    写在前面的话:Java虚拟机是一门学问,是众多Java大神们的杰作,由于我个人水平有限,精力有限,不能保证所有的东西都是正确的,这里内容都是经过深思熟虑的,部分引用原著的内容,讲的已经很好了,不在累述 ...

  7. java 栈和栈帧

    文章转载自:http://www.tuicool.com/articles/URZrMnb jvm为每个新创建的线程都分配一个堆栈.堆栈以帧为单位保存线程的状态.jvm对堆栈只进行两种操作:以帧为单位 ...

  8. 详细解析Java虚拟机的栈帧结构

    欢迎关注微信公众号:万猫学社,每周一分享Java技术干货. 什么是栈帧? 正如大家所了解的,Java虚拟机的内存区域被划分为程序计数器.虚拟机栈.本地方法栈.堆和方法区.(什么?你还不知道,赶紧去看看 ...

  9. 【转载】深入理解Java虚拟机笔记---运行时栈帧结构

    栈帧(Stack Frame)是用于支持虚拟机进行方法调用和方法执行的数据结构,它是虚拟机运行时数据区的虚拟机栈(Virtual Machine Stack)的栈元素.栈帧存储了方法的局部变量表,操作 ...

随机推荐

  1. Android WebView的使用(用来显示网页)

    1.WebView介绍 2.URL介绍 简单说就是网址. 3.java后台代码 package com.lucky.test34webview; import android.support.v7.a ...

  2. QQ在线状态的使用

    在网页中显示QQ在线状态并点击后发起对话,是很多门户网站常见的一个功能,这两天就碰到这样一个.原以为很简单,结果还是折腾了半天,虽然是个小问题,但也值得记录一下. 按以前的经验,网上有很多QQ在线代码 ...

  3. rest-assured的根路径(root path)和URL编码(URL Encoding)

    一.根路径(Root path) 为了避免在body方法中使用重复的路径来断言,我们可以指定一个根路径(root path),比如: 我们以前的写法是: when(). get("/some ...

  4. Visual Studio Ultimate 2013 免费下载地址

    ed2k://|file|cn_visual_studio_2010_ultimate_x86_dvd_532347.iso|2685982720|4AE6228933DDE49D9BFA4C3467 ...

  5. 设置select不可修改

    <s:select id="notSelectChange" list="#{'1':'表示每月几号','2':'表示每季度第几天','3':'表示每年第几月'}& ...

  6. ssm框架中的乱码问题的解决

    在搭建ssm框架过程中可能会出现乱码的问题,解决的最好方法就是不管在哪儿都设置为utf-8: 统一编码格式,所有的都设置为utf-8: 首先的就是将所有的请求设置为utf-8: 设置post请求的编码 ...

  7. Covering(矩阵快速幂)

    Bob's school has a big playground, boys and girls always play games here after school.  To protect b ...

  8. linux驱动之设备模型

    linux 设备驱动模型 inux2.6提供了新的设备模型:总线.驱动.设备.基本关系简要的概括如下: 驱动核心可以注册多种类型的总线. 每种总线下面可以挂载许多设备.(通过kset devices) ...

  9. PIE SDK图层属性

    1. 功能简介 通过查看图层属性可以对图层的基本信息(一般信息,来源,注释,字段信息等)有所了解 ,下面就基于PIE SDK,介绍查看图层属性功能的实现. 2. 功能实现说明 2.1. 实现思路及原理 ...

  10. linux 运维基础之VM中安装centos6.X

    VM中安装centos详细教程 图片讲解: