Class 03: 8051 Microcontroller Memory Organisation
Class 03: 8051 Microcontroller Memory Organisation
Class 03: 8051 Microcontroller Memory Organisation
Microcontroller Memory
organisation
Memory Organisation
Data Memory
Data Memory in a Microcontroller is responsible for storing values
of variables, temporary data, intermediate results and other data for
proper operation of the program.
Program Memory
But almost all modern variants of 8051 Microcontroller have 256B of RAM.
Register Bank Area
• In the first 128B of RAM (from 00H to 7FH), the
first 32B i.e. memory from addresses 00H to 1FH
consists of 32 Working Registers that are
organized as four banks with 8 Registers in each
Bank.
• But only one register bank can be used at any
(Stack)
point in time. To select the register bank, two bits
of PSW (Program Status Word) are used.
• Each Bank consists of 8 registers named as R0 –
R7. Each Register can be addressed in two ways:
either by name or by address.
How to Switch Register Banks
PSW Register (all 8051 and 251 variants) RS10 RS21 Bank Selected
0 0 Bank0
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
CY AC FO RS1 RS0 OV UD P 0 1 Bank1
1 0 Bank2
1 1 Bank3
Stack
• The stack is a section of RAM used by the
CPU to store information temporarily. This
information could be data or an address. The
CPU needs this storage area since there are
only a limited number of registers.
• Here the stack pointer (SP) is an only 8-bit
register, because the internal RAM area is only
in range 00H to 7FH, and when all register
banks are being used, the stack location will be
in range 30H to 7FH. So in such a case, the SP
will be initialized with 2FH.
How Stacks are Accessed
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. For
example, the instruction "PUSH 1" pushes register R1 onto the stack.
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