8051 Memory Organization
8051 Memory Organization
Computer Instructions
Computer instructions are the basic components of a machine language program. They
are also known as macro operations, since each one is comprised of a sequences of
microoperations.
Each instruction initiates a sequence of microoperations that fetch operands from registers
or memory, possibly perform arithmetic, logic, or shift operations, and store results in registers
or memory.
In addition to the opcode, many instructions also contain one or more operands, which
indicate where in registers or memory the data required for the operation is located. For example,
and add instruction requires two operands, and a not instruction requires one.
The term addressing mode refers to the way in which the operand of an instruction is
specified. The operand can be directly given in an instruction, it can be the address of location
where data is stored or it can even be a pointer to memory location where data is stored.
The 8051 microcontroller's memory is divided into Program Memory and Data Memory.
Program Memory (ROM) is used for permanent saving program being executed, while Data
Memory (RAM) is used for temporarily storing and keeping intermediate results and variables.
8051 Microcontroller has both Internal ROM and Internal RAM. If the internal memory is
inadequate, you can add external memory using suitable circuits.
Internal ROM
External ROM
Internal RAM
External RAM
Program Memory (ROM) of 8051 Microcontroller
In 8051 Microcontroller, the code or instructions to be executed are stored in the Program
Memory, which is also called as the ROM of the Microcontroller. The original 8051
Microcontroller by Intel has 4KB of internal ROM.
In case of 4KB of Internal ROM, the address space is 0000H to 0FFFH. If the address space i.e.
the program addresses exceed this value, then the CPU will automatically fetch the code from the
external Program Memory.
1) Only Internal ROM: 8051 has 4 KB internal ROM. In many cases this size is sufficient
and there is no need for connecting External ROM. All addresses from 0000H to 0FFFH
will be accessed from internal ROM.
2) Internal and external ROM: If the size of internal ROM is insufficient, systems can use a
combination of both Internal and External ROM. All addresses from 0000H to 0FFFH
will be accessed from Internal ROM. Addresses 1000H to FFFH will be accessed from
External ROM.
3) Only External ROM: If the user choose not to use Internal ROM because of reasons like
the program stored in the Internal ROM becoming invalid or outdated or if the system
needs to be upgraded etc. upto 64 KB of external ROM can be connected.
The Data Memory or RAM of the 8051 Microcontroller stores temporary data and intermediate
results that are generated and used during the normal operation of the microcontroller. Original
Intel’s 8051 Microcontroller had 128B of internal RAM. The address range is 00H to 7FH.
Memory addresses from 00H to 7FH is divided in to Working Registers (organized as Register
Banks), Bit – Addressable Area and General Purpose RAM (also known as Scratchpad area).
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. The 4 banks are named as Bank0, Bank1,
Bank2 and Bank3. Each Bank consists of 8 registers named as R0 – R7. Each Register can be
addressed in two ways: either by name or by address.
Eg. Location 00H can be accessed as R, if Bank 0 is the active bank.
It can also be accessed as location 00H irrespective of which bank is the active bank.
The upper 128B of the RAM i.e. memory addresses from 80H to FFH is allocated for Special
Function Registers (SFRs). SFRs control specific functions of the 8051 Microcontroller. Some of
the SFRs are I/O Port Registers (P0, P1, P2 and P3), PSW (Program Status Word), A
(Accumulator), IE (Interrupt Enable), PCON (Power Control), etc.
SFRs are 8 bit registers. SRFs Memory addresses are only direct addressable. SFRs are allotted
addresses from 80H to FFH. Even though some of the addresses between 80H and FFH are not
assigned to any SFR, they cannot be used as additional RAM area.
In some microcontrollers, there is an additional 128B of RAM, which share the memory address
with SFRs i.e. 80H to FFH. But, this additional RAM block is only accessed by indirect
addressing.
ADDRESSING MODES
The term addressing mode refers to the way in which the operand of an instruction is specified.
Information contained in the instruction code is the value of the operand on the address of the
result/operand. The CPU access data in various ways. The 8051 supports the following types of
addressing modes.
1. Immediate mode
2. Direct addressing
3. Indirect addressing
4. Register instructions
5. Register specific
6. Indexed addressing
Symbols
1. IMMEDIATE ADDRESSING :
In immediate addressing mode, an 8/16 bit immediate data / constant is specified in the
instruction itself. A ‘#’ character is put before the data, to identify it as a data value and not as an
address. The destination register to which the constant data must be copied should be the same
size as the operand mentioned in the instruction.
Immediate Addressing is very fast as the data to be loaded is given in the instruction
itself.
E.g.
MOV A, #35H :- Move the immediate data 35H given in the instruction to A-register.
MOV DPTR, #3000H :- Load the immediate 16-bit constant given in the instruction in
DPTR (Data pointer). This constant will be an address of data memory location.
2. DIRECT ADDRESSING :
In direct addressing mode, the address of the data is directly specified in the instruction. The
direct address can be the address of an internal data RAM location (00H to 7FH) or address of
special function register (80H to FFH).
Most assemblers and compilers provide equates or standard symbol name for the SFRs and I/O
ports , so that SFRs names may be used in lieu of its direct address.
For e.g. P0 stands for address 80H , TMOD stands for address 89H etc.
E.g.
MOV A, 35 H :- This instruction will move the RAM location 35H to A-register
(Accumulator).
ADD A,#100 : Immediate data 100(decimal) is added to the contents of accumulator. For
specifying a hex number, it should be followed by H
MOV A,80H or MOV A,P0: Move contents of Port 0 (SFR at address 80H) to A
MOV R0,89H : Here 89H is the address of a special function register TMOD
MOV 20H,30H: Location 20H gets the content of location 30H
REFERENCES