Embedded之Stack之一
1 Intro
When a program starts executing, a certain contiguous section of memory is set aside for the program called the stack.

The stack pointer is usually a register that contains the top of the stack. The stack pointer contains the smallest address x such that any address smaller than x is considered garbage, and any address greater than or equal to x is considered valid.
stack bottom The largest valid address of a stack. When a stack is initialized, the stack pointer points to the stack bottom.
stack limit The smallest valid address of a stack. If the stack pointer gets smaller than this, then there's a stack overflow (this should not be confused with overflow from math operations).
2 Push
There are two operations on the stack: push and pop.
push You can push one or more registers, by setting the stack pointer to a smaller value (usually by subtracting 4 times the number of registers to be pushed on the stack) and copying the registers to the stack.
push: addi $sp, $sp, - # Decrement stack pointer by
sw $r3, ($sp) # Save $r3 to stack

The diagram on the left shows the stack before the push operation.
The diagram in the center shows the stack pointer being decremented by 4.
The diagram on the right shows the stack after the 4 bytes from register 3 has been copied to address 0x000f fffc
3 Pop
pop You can pop one or more registers, by copying the data from the stack to the registers, then to add a value to the stack pointer (usually adding 4 times the number of registers to be popped on the stack)
pop: lw $r3, ($sp) # Copy from stack to $r3
addi $sp, $sp, # Increment stack pointer by

The diagram on the left is the initial state of the stack.
The data is copied from the stack to the register 3. Thus, the diagram in the center is the same as the one on the left. If I had drawn a picture of the contents of register 3, it would have been updated with the data from the stack.
Then, the stack pointer is moved down (shown in the diagram on the right).
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 Function Programming languages make functions easy to maintain and write by giving each function i ...
- 【转载】关于Embedded Linux启动的经典问题
转载自:http://linux.chinaunix.net/techdoc/install/2009/04/13/1107608.shtml 发信人: armlinux (armlinux), 信区 ...
- 试验Windows Embedded Standard 7 Service Pack 1 Evaluation Edition
=========================================== 是否支持再使用 RT 7 Lite 精简 ? ================================= ...
- Windows Embedded Compact 7新特性
Windows® Embedded Compact 7是Windows Embedded CE的下一代产品,而Windows Embedded CE这款操作系统面向占用资源少的新颖设备.Windows ...
- Using QEMU for Embedded Systems Development
http://www.opensourceforu.com/2011/06/qemu-for-embedded-systems-development-part-1/ http://www.opens ...
- Important Programming Concepts (Even on Embedded Systems) Part V: State Machines
Earlier articles in this series: Part I: Idempotence Part II: Immutability Part III: Volatility Part ...
- Install LAMP Stack On Ubuntu 16.04
原文:http://www.unixmen.com/how-to-install-lamp-stack-on-ubuntu-16-04/ LAMP is a combination of operat ...
- ELK Stack (2) —— ELK + Redis收集Nginx日志
ELK Stack (2) -- ELK + Redis收集Nginx日志 摘要 使用Elasticsearch.Logstash.Kibana与Redis(作为缓冲区)对Nginx日志进行收集 版本 ...
随机推荐
- 洛谷 1486 郁闷的出纳员【Treap】
[题意概述] 要求维护一个序列支持以下操作: 1,插入元素x: 2,把序列的所有元素加上x: 3,把序列的所有元素减去x,同时低于一个给定的下限的元素马上被删除: 4,询问序列中第k大的元素. [题解 ...
- PAT 1105 Spiral Matrix
This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasi ...
- 洛谷 P1972 BZOJ 1878 [SDOI2009]HH的项链
题目描述 HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH 不断地收集新的贝壳,因此,他的项链变得越来越长. ...
- js es6 Object.freeze
将对象冻结,使用Object.freeze方法 const foo = Object.freeze({}); // 常规模式时,下面一行不起作用: // 严格模式时,该行会报错 foo.prop = ...
- C - Reading comprehension 二分法 求等比数列前N项和
Read the program below carefully then answer the question. #pragma comment(linker, "/STACK:1024 ...
- js递归解决汉诺塔问题
汉诺塔是一个印度的古老传说.有三个圆柱,其中一个圆柱上放着若干圆盘,这些圆盘从上到下,直径递增,利用一个辅助圆柱,将原来柱子上的圆盘放到另一个柱子上,依旧是从上到下直径递增. 汉诺塔是一个经典的递归案 ...
- www.pgcon.org 文档
https://www.pgcon.org/2016/schedule/attachments/ https://www.pgcon.org/2015/schedule/attachments/ ht ...
- qt on android之GPS信号的获取
0. 写在最前面 本人參考安晓辉大侠的一篇博文后.做了Qt on android的GSP相关的实验.为了后面不时之需.故而记录下来. 1. Qt on Android GPS系统流 ...
- 在Ubuntu 14.04 上安装 FTP 服务
1. sudo apt-get update 2. sudo apt-get install vsftpd 3. adduser sammy Assign a password when prompt ...
- VB.NET机房收费 & 抽象工厂模式
学习设计模式的时候,提到了一个专门訪问数据库的模式-抽象工厂模式,记得当时举样例理解的时候并未设计到数据库,仅仅是大概了了解了一下,如今对于机房收费系统涉及到了数据库的管理,借此机会好好学习一下.用常 ...