Unit 5-8051 Memory Organization
Unit 5-8051 Memory Organization
2
Memory Unit (internal and External)
Memory (8051)
5
8051- Registers and Internal Memory
6
Dayanandhan K, Sathyabama Institute of Science and Technology
8051- Internal Memory
Internal Memory
7
8051- Internal RAM Memory
Internal
Memory
Read/Write Memory
(R/W)
256 Bytes
Internal Memory
Read/Write Memory
(R/W)
128 Bytes 128 Bytes
256 Bytes
Address Address
00 H to 7F H 80 H to FF H
Read/Write Memory
Purpose three portions.
(R/W) Registers 1. 32 Bytes of Bank
256 Bytes
16 Bytes registers
128 Bytes Address 2. 16 Bytes of Bit-
20 H to 1F H Addressable
Bit
Address Registers
Addressable
00 H to 7F H Registers
3. 80 Bytes of General
Purpose Registers
32 Bytes
Address
00 H to 1F H
00 H Bank registers
128 Bytes of Read-Write Memory (RAM)
Addresses
Bank 0 Addresses
Bank 1 Addresses
Bank 2 Addresses
Bank 3
07 H R7 0F H R7 17 H R7 1F H R7
06 H R6 0E H R6 16 H R6 1E H R6
05 H R5 0D H R5 15 H R5 1D H R5
04 H R4 0C H R4 14 H R4 1C H R4
03 H R3 0B H R3 13 H R3 1B H R3
02 H R2 0A H R2 12 H R2 1A H R2
01 H R1 09 H R1 11 H R1 19 H R1
00 H R0 08 H R0 10 H R0 18 H R0
8 Bytes of 8 Bytes of 8 Bytes of 8 Bytes of
Bank 0 registers Bank 1 registers Bank 2 registers Bank 3 registers
11
For selecting a particular Bank, PSW register to be used.
The PSW Register
• Program Status Word is a “bit addressable” 8-bit register that has all the flags.
MSB LSB
PSW.7 PSW.6 PSW.5 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0
CY AC F0 RS1 RS0 OV - P
• Bit 3 & 4 (PSW.3 & PSW.4), RS0 & RS1, decides the Bank selection.
12
• Program Status Word is a “bit addressable” 8-bit register that has all the flags.
MSB LSB
PSW.7 PSW.6 PSW.5 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0
CY AC F0 RS1 RS0 OV - P
13
8051- Internal RAM- Bank Registers
MSB LSB
Internal Memory
PSW.7 PSW.6 PSW.5 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0
CY AC F0 RS1 RS0 OV - P
Read/Write Memory X X X 0 0
1 X X X
(R/W)
256 Bytes
RS1 RS0 Bank Selected SETB PSW.3 SETB The bit PSW.3 is SET-RS0=1
0 0
1 0–2
Bank 1 1nd
st Bank
Bank CLR PSW.4 CLR The bit PSW.4 is RESET-RS1=0
Instructions for Changing Bank registers
Selected bank
Bank 0 Addresses
Bank 1 Addresses
Bank 2 Addresses
Bank 3
Addresses
07 H R7 0F H R7 17 H R7 1F H R7
06 H R6 0E H R6 16 H R6 1E H R6
05 H R5 0D H R5 15 H R5 1D H R5
04 H R4 0C H R4 14 H R4 1C H R4
03 H R3 0B H R3 13 H R3 1B H R3
02 H R2 0A H R2 12 H R2 1A H R2
01 H R1 09 H R1 11 H R1 19 H R1
00 H R0 08 H R0 10 H R0 18 H R0
8 Bytes of 8 Bytes of 8 Bytes of 8 Bytes of 14
Bank 0 registers Bank 1 registers Bank 2 registers Bank 3 registers
BYTE 8051- Internal RAM- Bit Addressable Registers
ADDRESS
BIT ADDRESSES 16 BYTES OF BIT-ADDRESSABLE
2F 7F 7E 7D 7C 7B 7A 79 78
BYTE ADDRESSING
2E 77 76 75 74 73 72 71 70 To write data 94H, in byte address 20,
MOV 20, #94H
2D 6F 6E 6D 6C 6B 6A 69 68 Where 20 is the address and 94H is the data, as
shown in the figure below.
2C 67 66 65 64 63 62 61 60
This is termed as Byte Addressing, since 1
2B 5F 5E 5D 5C 5B 5A 59 58 byte of data is addressed.
2A 57 56 55 54 53 52 51 50 07 06 05 04 03 02 01 00
29 4F 4E 4D 4C 4B 4A 49 48 20 1 0 0 1 0 1 0 0
28 47 46 45 44 43 42 41 40
BIT ADDRESSING
27 3F 3E 3D 3C 3B 3A 39 38 To write bit 1, in bit address 03,
SETB 03H
26 37 36 35 34 33 32 31 30
Where the bit address 03H, is SET with bit 1
25 2F 2E 2D 2C 2B 2A 29 28 and
This is termed as Bit Addressing, since 1 bit of
24 27 26 25 24 23 22 21 20 address is addressed.
23 1F 1E 1D 1C 1B 1A 19 18
07 06 05 04 03 02 01 00
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08 20 1 0 0 1 1 1 0 0
20 07 06 05 04 03 02 01 00
15
16 BYTES OF BIT-ADDRESSABLE REGISTERS
8051- Internal RAM- General Purpose Registers
Internal Memory
The General Purpose Registers are BYTE
ADDRESSABLE only
Addresses
7F H To write data 3AH, in byte address 50,
Read/Write Memory
(R/W)
256 Bytes MOV 50, #3AH
80 bytes
30 H
80 Bytes of
General Purpose registers
16
8051- Internal RAM- Special Function Registers
(SFR)
Internal Memory
Read/Write Memory
(R/W)
256 Bytes
17
8051- Internal RAM- Special Function Registers (SFR)
18
Dayanandhan K, Sathyabama Institute of Science and Technology
The ACC – Accumulator
• Commonly used for move and arithmetic instructions.
• Can be referred to in several ways:
– Implicitly in op-codes.
– Referred to as ACC (or A) for instructions that allow specifying a
register.
– By its SFR address 0E0H.
• Bit addressable.
– ACC.2 means bit 2 of the ACC register.
19
The B Register
• Commonly used as a temporary register, much like a 9th
R register.
• Used by two op-codes
– MUL AB, DIV AB
• B register holds the second operand and will hold part of
the result
– Upper 8 bits of the multiplication result
– Remainder in case of division.
20
The DPL and DPH Registers
• 2 8-bit registers that can be combined into a 16-bit DPTR – Data
Pointer.
• Used by commands that access external memory
• Also used for storing 16bit values
mov DPTR, #data16
; setup DPTR with 16bit ext address
movx A, @DPTR
; copy mem[DPTR] to A
22
The PSW Register
• Program Status Word is a “bit addressable” 8-bit register
that has all the flags.
MSB LSB
CY AC F0 RS1 RS2 OV - P
• Bit addressable.
– First bit has the same address as the register.
– Example: P1 has address 90H in the SFR, so
• P1.7 or address 97H refer to the same bit.
24
The SBUF Register
• Serial Port Data Buffer.
• 2 registers at the same location
– One is read-only used for reading serial input
data.
• Serial Data Receive Buffer.
– The other is write-only used for storing serial
output data.
• Serial Data Transmit Buffer.
25
Timer Registers – T0 and T1
• The high and low bytes of the 16-bit down counting
register for timer/counter T0.
• Timer T0, consists of two 8 bit timer registers TL0 and
TH0.
• There is also a TH1 / TL1 pair for the T1 timer.
• There are several modes to operate both the timers.
26
Control Registers
• IP – Interrupt Priority.
• IE – Interrupt Enable.
• TMOD – Timer Mode.
• TCON – Timer Control.
• T2CON – Timer 2 Control (8052)
• SCON – Serial Port Control.
• PCON – Power Control (80C51).
27
8051- Internal Memory- ROM
Internal Memory
Address
4 Kilo Bytes of Internal Read-Only Memory (ROM), accessed by 0000 H to 0FFF H
internal 16 bit address bus and 8-bit data bus.
Only reading is possible from this ROM. Interrupt vector
addresses, are allotted in this ROM only.
The address ranges from 0000H to 0FFFH as shown in the
0000 H
figure beside.
4 KB of Read Only Memory (ROM)
This ROM shares address with external RAM.
External RAM has address from 1000H to FFFFH (60 KB)
Pin EA shall be 1 for access of internal ROM
29
8051- Internal RAM- STACK
Internal Memory • Bank 0 doesn’t involve in STACK operation. Only other Banks
are involved in stack operation.
Read/Write Memory
• Stack Pointer SP (8 Bit-Register) by default stores value 07H
(R/W)
256 Bytes
in it. The stack starts from 08H to FFH
• As stack is loaded by Push instructions, SP increases from
07 to FF and POP instruction decreases SP by one.
Addresses
Bank 1 Addresses
Bank 2 Addresses
Bank 3
0F H R7 17 H R7 1F H R7
0E H R6 16 H R6 1E H R6
0D H R5 15 H R5 1D H R5
0C H R4 14 H R4 1C H R4
0B H R3 13 H R3 1B H R3
0A H R2 12 H R2 1A H R2
09 H R1 11 H R1 19 H R1
08 H R0 10 H R0 18 H R0
SP=07 8 Bytes of 8 Bytes of 8 Bytes of 30
Bank 1 registers Bank 2 registers Bank 3 registers
8051- External Memory
External Memory
External Memory
65536 Byte
(64 KB) Only reading is possible from this ROM. User can once write a
Address
0000H - FFFFH Program using this ROM. This is called Program or Code
memory unit.
The address ranges from 0000H to FFFFH as shown in the
figure beside.
The instruction used to access this ROM is
MOVC A, @DPTR
Here DPTR (Data-Pointer) is used to access the address
stored in Data-Pointer. MOVC is a special MNEMONIC
used for External ROM.
Only Read can be done since it is a ROM and the
instruction cannot be MOVC @DPTR, A.
Pin EA shall be 0 for access of external ROM
32
8051- Possible Questions
33