Stack in 8051
RAM locations
from 08H to 1FH can be used as stack. Stack is used to store the data
temporarily.
Stack is last in first out (LIFO)
Stack pointer (SP) →
8bit register
It indicate current RAM address
available for stack or it points the top of stack.
Initially by default at 07H
because first location of stack is 08H.
After each PUSH instruction the
SP is incremented by one while in MC after PUSH instruction SP is decremented.
After each POP instruction the
SP is decremented
Example:
MOV R6,#25H;
MOV R1,#12H;
MOV R4,#OF3H;
PUSH 06H;
PUSH 01H; POP 04H;
if we want to use more than 24byte (08H to 1FH) of stack. We can change SP to point RAM address 30H to 7FH by MOV SP,
Conflicting of Register Banks and
Stack
We know
locations from 08H to 1FH is used as stack and it is also used as register bank.
If in the
program, we use the Register Bank 1 to 3 and also use the stack then conflicts
exist and error can be possible.
For removing this situation we use the
stack from location 30H to 7FH by shifting SP to 2FH.
MOV SP,#2FH;
16 bit register, it is divided into two parts DPH and
DPL.
DPH for Higher order 8 bits, DPL for lower order 8
bits.
DPTR, DPH, DPL these all are SFRs in 8051.
RAM scratch pad, there is extra 128 byte RAM which is used to store the SFRs
Following figure shows special function bit address, all access to the four I/O ports CPU register, interrupt control register, timer/counter, UART, power control are performed through registers between 80H and FFH.
Lesson meta keywords and meta description:
Write a public review