STACK 栈

今天又看了一遍stack(栈),有些知识点总是记不清,留个笔记以后看。

主要参考的Wiki:STACK 



A typical stack, storing local data and call information for nested procedure calls (not necessarily nested procedures!).
This stack grows downward from its origin. The stack pointer points to the current topmost datum on the stack.
A push operation decrements the pointer and copies the data to the stack; a pop operation copies data from the stack and then increments the pointer.
  • 定义一个局部变量对应push入栈操作
    即: 最开始时stack pointer指向bottom,然后push操作会将stack pointer向下移动。
    注意这里的“向下”只是指图里是向下的,并没有说是朝着实际内存的高地址还是低地址移动。
    图中的序号28~0只是示意,我觉得写成0~28也可以,都与实际内存地址的高地无关。

A stack is usually represented in computers by a block of memory cells, with the "bottom" at a fixed location, and the stack pointer holding the address of the current "top" cell in the stack. The top and bottom terminology are used irrespective of whether the stack actually grows towards lower memory addresses or towards higher memory addresses.
  • “bottom”是指固定不动的那端,也就是图中的stack origin;
  • “top”是指stack pointer所指的那端,是来回移动的;
  • 这里所说的"bottom"和“top”,与“stack实际是朝着低地址增长还是朝着高地址增长”,是没有任何关系的;
    VxWorks中,stack pointer是朝着低地址移动,还是朝着高地址移动?

If a pop operation on the stack causes the stackpointer to move past the origin of the stack, a stack  underflow occurs.

If a push operation causes the stack pointer toincrement or decrement beyond the maximum extent of the stack, a stack overflow occurs.

  • underflow是指stack pointer超过了origin of the stack,也就是超过了栈底bottom的情况;
  • ovrflow是指stack pointer超过了stack的最大范围的情况;

If the stack points to the current topmost item, the stack pointer will be updated before a new item is pushed onto the stack; if it points to the next available location in the stack, it will be updated after the new item is pushed onto the stack.
  • 当有新的元素入栈时,stack pointer会先被更新,而后才将这个新元素放到栈里;
  • 当有元素出栈时,会先将元素出栈,而后再更新stack pointer;
    为什么这样呢?保护什么?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值