Stack and its Operations
Stack in the 8051
The stack is a section of a RAM used by the CPU to
store information such as data or memory address on temporary basis. And which
work on LIFO (Last in and first out) basis. The CPU needs this storage area considering
limited number of registers.
As the stack is a section of a RAM, there are
registers inside the CPU to point to it. The register used to access the stack
is known as the stack pointer register.
The storing operation of a CPU register in the stack
is known as a PUSH, and getting the contents from the stack back
into a CPU register is called a POP.
Pushing into the Stack
In the 8051, the stack pointer (SP) points to the last used
location of the stack. When data is pushed onto the stack, the stack pointer
(SP) is incremented by 1. When PUSH is executed, the contents of the register
are saved on the stack and SP is incremented by 1. To push the registers onto
the stack, we must use their RAM addresses.
Popping from the Stack
Popping the contents of the stack back into a given register is
the opposite to the process of pushing. With every pop operation, the top byte
of the stack is copied to the register specified by the instruction and the
stack pointer is decremented once.
No comments:
Post a Comment