Stack and Stack Pointer Register
Stack :
The stack is a part of RAM used by the CPU to store information temporarily. This information may be either data or address.
The CPU needs this storage area as there are only a limited amount
The register used to access stack is called stack pointer.
Stack Pointer :
It is an 8-bit register, which indicates the last byte pushed on the stack. It is automatically incremented during execution of PUSH, CALL instructions. It is also Incremented by interrupt call.
It is decremented by POP, RET, RETI instructions. It can point all Internal 128 bytes of RAM locations. During stack write operation, the microprocessor increments stack pointer by 1 and saves a byte on the stack During stack read operation, the microprocessor reads a byte from the stack and then decrements stack pointer by 1. Hence, stack pointer must be initialized with lowest stack address.
The SP is initialized with 07H after reset; this causes the stack to begin to location 08H. The stack is generally placed in the general-purpose area of the Internal RAM. It is never placed in the external data memory
Example: MOV R6, #35H
MOV R1 #2OH
PUSH 6
PUSH 1
In the above instructions, the contents of the Registers R6 and R1 are moved to
stack and they occupy the 08 and 09 locations of the stack. Now the contents of the SP are incremented by two and it is OA Similarly, POP 3 instruction POPS the contents of the stack into R3 register. So, now the contents of the SP is decremented by 1.
0 Comments