Embedded之Stack之二
1 Function
Programming languages make functions easy to maintain and write by giving each function its own section of memory to operate in.
For example, suppose you have the following function.
int pickMin( int x, int y, int z ) {
int min = x ;
if ( y < min )
min = y ;
if ( z < min )
min = z ;
return min ;
}
You declare parameters x, y, and z. You also declare local variables, min. You know that these variables won't interfere with other variables in other functions, even if those functions use the same variable names.
In fact, you also know that these variables won't interfere with separate invocations of itself.
2 Stacks and functions
Imagine we're starting in main() in a C program. The stack looks something like this
Suppose, inside of body of main() there's a call to foo(). Suppose foo() takes two arguments. One way to pass the arguments to foo() is through the stack. Thus, there needs to be assembly language code in main() to "push" arguments for foo() onto the the stack.
Once we get into code for foo(), the function foo() may need local variables, so foo() needs to push some space on the stack.
We've added a new pointer called FP which stands for frame pointer. The frame pointer points to the location where the stack pointer was, just before foo() moved the stack pointer for foo()'s own local variables.
When exit foo() the stack looks just as it did before we pushed on foo()'s stack frame, except this time the return value has been filled in.
Once main() has the return value, it can pop that and the arguments to foo() off the stack.
Embedded之Stack之二的更多相关文章
- Embedded之Stack之三
Stack Overflow While stacks are generally large, they don't occupy all of memory. It is possible to ...
- Embedded之Stack之一
1 Intro When a program starts executing, a certain contiguous section of memory is set aside for the ...
- 【一天一道LeetCode】#225. Implement Stack using Queues
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Impleme ...
- Spark性能优化【Stack Overflow】
一.异常情况 Stack Overflow 二.异常分析 之所以会产生Stack Overflow,原因是在Stack方法栈中方法的调用链条太长的原因导致的,一般情况有两种: 1.过于深度的递归[常见 ...
- C++ STL——stack和queue
目录 一 stack容器 二 queue容器 注:原创不易,转载请务必注明原作者和出处,感谢支持! 注:内容来自某培训课程,不一定完全正确! 栈和队列作为经典的数据结构,我们再熟悉不过了.C++ ST ...
- SpringBoot笔记(7)
一.单元测试 1.JUnit5简介 Spring Boot 2.2.0 版本开始引入 JUnit 5 作为单元测试默认库 作为最新版本的JUnit框架,JUnit5与之前版本的Junit框架有很大的不 ...
- 痞子衡嵌入式:IAR内部C-SPY调试组件配套宏文件(.mac)用法介绍
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是IAR内部C-SPY调试组件配套宏文件(.mac)用法. 痞子衡之前写过一篇 <JLink Script文件基础及其在IAR下调用 ...
- MATLAB绘图
matlab绘制散点图 clc,clear x=[11.9,11.5,14.5,15.2,15.9,16.3,14.6,12.9,15.8,14.1]; y=[196.84,196.84,197.14 ...
- 剑指offer系列34----按之字形顺序打印二叉树
[题目]请实现一个函数按照之字形打印二叉树, * 即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印, * 其他行以此类推. 未优化,不是最优解,博主用的是队列 ...
随机推荐
- eclipse 快捷键及使用技巧
一.程序的编译和运行的环境配置(一般不改) window -- Preferences -- Java 编译环境:Compiler 默认选中的就是最高版本. 运行环境:Installed JREs 默 ...
- Android: Could not find com.android.support:support-v4:21.0.0
安装Android Support Repository即可解决这个问题.
- Android之怎样使用ListView列表视图
ListView 列表视图创建方法: (1)直接使用ListView 组件创建 (2)让Activity继承ListActivity实现 第一种:在XML中直接使用ListView 组件创建 在val ...
- Cocos2d-X开发中国象棋《三》開始场景的实现
在前面两节(第一节.第二节)中介绍了中国象棋的功能和project文件.在这篇博客中将介绍中国象棋的開始场景的实现 在写代码前先理清一下实现開始场景的思路: 1.打开游戏后进入開始场景,场景上显示一个 ...
- mysql中 show table status 获取表信息
用法 mysql>show table status; mysql>show table status like 'esf_seller_history'\G; mysql>show ...
- 卡尔曼滤波(Kalman Filter) 的进一步讨论
我们在上一篇文章中通过一个简单的样例算是入门卡尔曼滤波了.本文将以此为基础讨论一些技术细节. 卡尔曼滤波(Kalman Filter) http://blog.csdn.net/baimafujinj ...
- vmware上安装ubuntu和vmwaretools
一.平台:win7操作系统 vmware 10.0.0 ubuntu 14.04 二.vmware下安装ubuntu: 具体安装步骤可以按照推荐的来,但是要注意一定要先创建新的虚拟机,之后再安装u ...
- C# Socket 您的主机中的软件中止了一个已建立的连接 An established connection was aborted by the software in your host machine
http://tieba.baidu.com/p/3223234493 问题: 服务端在接收客户端数据的时候,抛了个异常出来:System.Net.Sockets.SocketException: 您 ...
- ConfigSections配置
如果配置文件中包含了configSections,那么configSections的下一个节点,必须是configSections里面的元素 <configSections> <se ...
- bzoj 1034 [ ZJOI 2008 ] 泡泡堂BNB —— 贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1034 一开始想了个很麻烦的贪心做法,对于每个 a[i],找第一个大于它的 b 匹配…… 然后 ...