0% found this document useful (0 votes)
6 views

5 Internal RAM Structure

Uploaded by

mg495753
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

5 Internal RAM Structure

Uploaded by

mg495753
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

STRUCTURE OF INTERNAL RAM OF 8051

8051 has a 128 Bytes of internal RAM.


These are 128 locations of 1 Byte each.
The address range is 00H… 7FH.
This RAM is used for storing data.
It is divided into three main parts: Register Banks, Bit addressable area and a general purpose
area.
REGISTER BANKS

1) The first 32 locations (Bytes) of the Internal RAM from 00H… 1FH, are used by the
programmer as general purpose registers.
2) Having so many general purpose registers makes programming easier and faster.
3) But as a downside, this also vastly increases the number of opcodes
4) Hence the 32 registers are divided into 4 banks, each having 8 Registers R0… R7.
5) The first 8 locations 00H… 07H are registers R0… R7 of bank 0.
6) Similarly locations 08H… 0FH are registers R0… R7 of bank 1 and so on.
A register can be addressed using its name, or by its address.
Eg: Location 00H can be accessed as R0, if Bank 0 is the active bank.
MOV A, R0; “A” register gets data from register R0.
It can also be accessed as Location 00H, irrespective of which bank is the active bank.
MOV A, 00H; “A” register gets data from Location 00H.
7) The appropriate bank is selected by the RS1, RS0 bits of PSW.
Since PSW is available to the programmer, any Bank can be selected at run-time.
8) Bank 0 is selected by default, on reset.

BIT ADDRESSABLE AREA

1) The next 16-bytes of RAM, from 20H… 2FH, is available as Bit Addressable Area.
2) We can perform ordinary byte operations on these locations, as well as bit operations.
3) As each location has 8-bits, we have a total of  16 × 8 = 128 Addressable Bits.
4) These bits can be addressed using their individual address 00H … 7FH.
SETB 00H; Will store a “1” on the LSB of location 20H
CLR 07H; Will store a “0” on the MSB of location 20H
5) Normal “BYTE” operations can also be performed at the addresses: 20H … 2FH.
MOV 20H, #00H; Will store a “0” on all 8-bits of location 20H.
6) Here is something very interesting to know and will also help you understand further topics.
The entire internal RAM is of 128 bytes so the address range is 00H… 7FH.
The bit addressable area has 128 bits so its bit addresses are also 00h… 7FH.
7) This means every address 00H… 7FH can have two meanings, it could be a byte address or a
bit address.
8) This does not lead to any confusion, because the instruction in which we use the address,
will clearly indicate whether it is a bit operation or a byte operations.
SETB, CLR etc. are bit ops whereas ADD, SUB etc. are byte operations.
9) SETB 00H; This is a bit operation.
It will make Bit location 00H contain a value “1”.
10) MOV A, 00H; This is a byte operation.
“A” register will get 8-bit data from byte location 00H.

GENERAL PURPOSE AREA

1) The general-purpose area ranges from location 30H … 7FH.


2) This is an 80-byte area which can be used for general data storage.
STACK OF 8051

1) Another important element of the Internal RAM is the Stack.


2) Stack is a set of memory locations operating in Last In First Out (LIFO) manner.
3) It is used to store return addresses during ISRs and also used by the programmer to store
data during programs.
4) In 8051, the Stack can only be present in the Internal RAM.
5) This is because, SP which is an 8-bit register, can only contain an 8-bit address and
External RAM has 16-bit address.
6) On reset SP gets the value 07H.
7) Thereafter SP is changed by every PUSH or POP operation in the following manner:

PUSH: POP:
SP  SP + 1 Data  [SP]
[SP]  New data SP  SP – 1

8) The reset value of SP is 07H because, on the first PUSH, SP gets incremented and then data
is pushed on to the stack. This means the very first data will be stored at location 08H.
9) This does not affect the default bank (0) and still gives the stack, the maximum space to
grow.

10) The programmer can relocate the stack to any desired location by simply putting a new
value into SP register.

You might also like