This article presents the stack memory area.
The memory stack may be thought as a bulding down in memory.The stack pointer sp register is adjusted to point to the next stack location for every word pushed onto the stack.The current location in the sp represents the location of the last word pushed onto the stack.
Please have a look at: Stack and stack pointer , Data structures
In Keil ide we observe two main stacks. The system stack which contain return address for CALL instructions and also stores registers used for local register variables. The stack pointer for this area is sp .The user stack: it includes the main part that is 0x200= 512 bytes long which stores arguments to a called function and two small parts each one 0x20 bytes long which store the returning address from an interrupt.The stack pointer for the user stack is R0 rigister.
A technique to see what part of stack is used from an application is to fill the stack with a known word (at this example with 0xdcba) and to find the area that is overwritten. An easy way to fill the system stack is to use _push_() and _pop_ () functions. We can do overflows and underflows also.
You can find stack's areas in the projct .map file.
The C code The result
Exercise: Change the values of k and l integers of the C code and play doing stack overflows and underflows.Watch the stack pointer sp , doing step by step execution.
Stack needs a lot of ink to write, coming back...