Stack Types. Since it is left to the software to implement a stack, different implemenation choices result different types of stacks. There are two types of stack depending on how the stack grows.
- Ascending stack
- In a push the stack pointer is incremented, i.e the stack grows towards higher address. Descending stack
- In a push the stack pointer is decremented, i.e the stack grows towards lower address.
There are two types of stack depending on what the stack pointer points to.
- Empty stack
- Stack pointer points to the location in which the next item will be stored. A push will store the value, and increment the stack pointer. Full stack
- Stack pointer points to the location in which the last item was stored. A push will increment the stack pointer and store the value.
Four different stacks are possible - full-ascending, full-descending, empty-ascending, empty-descending. All 4 can be implemented using the register load store instructions.
UCOS-II 中的下面写法, 可以无论cpu stack是full-ascending, full-descending, empty-ascending, empty-descending. stack都是没有问题的。os的代码跟平台无关
#if OS_STK_GROWTH == 1u
(void)OSTaskCreate(OS_TaskIdle,
(void *)0,
&OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1u],
OS_TASK_IDLE_PRIO);
#else
(void)OSTaskCreate(OS_TaskIdle,
(void *)0,
&OSTaskIdleStk[0],
OS_TASK_IDLE_PRIO);
#endif
本文介绍了两种主要的堆栈类型:递增堆栈和递减堆栈,并探讨了堆栈指针的不同指向方式如何影响堆栈的实现。此外,还详细解释了UCOS-II操作系统中如何通过条件编译适配不同类型的堆栈。
29

被折叠的 条评论
为什么被折叠?



