The Stack Pointer (SP)
The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit (1-byte) value. The Stack Pointer is used to indicate where the next value to be removed from the stack should be taken from.When there is to push a value onto the stack, the 8051 first increments the value of SP and then stores the value at the resulting memory location.When there is to pop a value off the stack, the 8051 returns the value from the memory location indicated by SP, and then decrements the value of SP.
This order of operation is important. When the 8051 is initialized SP will be initialized to 07h. If there is to immediately push a value onto the stack, the value will be stored in Internal RAM address 08h. This makes sense taking into account what was mentioned two paragraphs above: First the 8051 will increment the value of SP (from 07h to 08h) and then will store the pushed value at that memory address (08h).SP is modified directly by the 8051 by six instructions: PUSH, POP, ACALL, LCALL, RET, and RETI. It is also used intrinsically whenever an interrupt is triggered.
Comments
Post a Comment