stack type, full-ascending, full-descending, empty-ascending, empty-descending

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


你可能感兴趣的:(stack type, full-ascending, full-descending, empty-ascending, empty-descending)