Friday, March 25, 2011

sp

sp

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.

POINTER指向下一個要被POP出去的東西

When you push a value onto the stack, the 8051 first increments the value of SP and then stores the value at the resulting memory location.

PUSH時,(SP)的值(ADDR)會+1,然後東西會存到(SP)+1的位置

When you 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.

POP時,先取值後,才把(SP) -1

This order of operation is important. When the 8051 is initialized SP will be initialized to 07h.

If you immediately push a value onto the stack, the value will be stored in Internal RAM address 08h.

初始的SP值是07H,所以第一個PUSH會被放在08H( INNER RAM )

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 (more on interrupts later. Dont worry about them for now!).



No comments:

Post a Comment