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

最新文章

  1. SQL语句-创建索引
  2. 3. Android程序生成步骤
  3. 栈的应用-四则表达式(C#代码实现)
  4. iOS UIButton加在window上点击无效果问题
  5. 企业移动互联网O2O微信支付流程图
  6. Spring中给Bean注入集合
  7. Struts框架中struts-config.xml文件配置小结
  8. Maven打包时去掉项目版本号
  9. javascript函数大全
  10. Vue 路由的嵌套
  11. centos7搭建kafka集群-第二篇
  12. Flutter开发中的几个常用函数
  13. 函数和常用模块【day06】:json模块(十一)
  14. 20145225《网络对抗》Exp8 Web基础
  15. Android JNI学习(五)——Demo演示
  16. JS(微信小程序)处理银行卡号
  17. bzoj 2120
  18. Windows上Tomcat启动,服务中没有Tomcat
  19. 洛谷P2676 超级书架 题解
  20. jquery.validate校验+jquery.form提交,配合使用

热门文章

  1. Android 连接服务器,并进行相关操作
  2. RNA-seq分析htseq-count的使用
  3. [FJOI2017]矩阵填数
  4. BZOJ - 4520 K远点对
  5. SQL批量提交修改业务
  6. 单个html使用axios调用接口传参
  7. [转] JAVA从本机获取IP地址
  8. mongodb的增删改查
  9. RedisClient 连接redis 提示 ERR Client sent AUTH, but no password is set
  10. Python+Selenium定位元素的方法