Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

UNIT II

MEMORY ORGANIZATION : 8051 microcontroller memory is classified as

ON CHIP MEMORY (PROGRAM MEMORY AND DATA MEMORY)


OFF CHIP MEMORY (PROGRAM MEMORY AND DATA MEMORY)

The 8051 has two types of memory and these are program memory and
data memory. Program memory (ROM) is used to permanently save the program
being executed. While data memory (RAM) is used to store data temporarily and
intermediate results created during the operation of microcontroller.

EXTERNAL MEMORY:

PROGRAM MEMORY: The 64kb of program memory space of 8051 is divided into
internal and external memory.
Means 4kb is internal program memory and 60kb is external memory.

FFFFH FFFFH
External
Program EXTERNAL
Memory
PROGRAM
(60KB)
MEMORY
1000H
(64KB)
000FH
Internal
Program
Memory
0000H 0000H
EA=1 EA=0
If EA pin is high, then 8051 executed from the internal program
memory until the address executes 0FFFH. After that location 1000H through
FFFFH are executed from the external memory portion. If EA pin is low executes
instruction from external program memory only.
DATA MEMORY: 8051 supports 64 KB of external data memory in addition to 256
bytes of internal data memory. The external data memory is accessed using 16 bit
address lines and its address varies from 0000H to FFFFH. The general block
diagram of data memory is shown below.

FFFFH
EXTERNAL
DATA
MEMORY
(64KB)
0000H

INTERNAL MEMORY :
PROGRAM MEMORY: 8051 microcontroller supports 4KB of internal ROM for
program. This internal ROM can be accessed by using EA pin. General block
diagram of program memory as shown below.

0FFFH INTERNAL
PROGRAM
MEMORY
4 KB

0000H
DATA MEMORY: The total data memory of 8051 is 256 bytes these can be
divided into two 128 bytes of memory. The 128 bytes of memory segment is used
for general purpose storage other 128 bytes of memory is used for special
purpose storage (special function register only).
00H 80H

BANK 0
07H
08H

BANK 1
0FH
10H

17HBANK 2 18H

BANK 3
20H
(16)

BIT

ADDRESSABLE

2FH REGISTERS 30H


GENERAL PURPOSE

REGISTERS

(SCRATCH PAD AREA) 7FH FFH

REGISTER BANKS: There are four register banks supported by 8051 and each bank
contains eight 8 bit registers denoted by register banks 0,1,2,3 (total number of
registers is 32), the registers in each bank denoted by R0, R1….. R7.

RS0 RS1 REGISTER BANK ADDRESS


0 0 0 00H – 07H
0 1 1 08H – 0FH
1 0 2 10H – 17H
1 1 3 18H – 1FH
BIT ADDRESSABLE AREA: 8051 microcontroller has 16 bit addressable registers,
which can be addressed from 20H to 2FH. It can be accessed either bit or Byte
wise. These bits can be individually set, cleared, complimented etc using bit
manipulation instructions.
SCRATCH PAD AREA: Location 30H to 7FH are available as data RAM or
scratchpad area locations. These can store any data like partial results. In general
it can be used as general purpose memory location.
REGISTERS:

DATA POINTER (DPTR): DPTR register is not a true one because it doesn’t
physically exist. It contains to separate registers: DPH (data pointer high) and
DPL (data pointer low). For this reason it may be treated as 16 – bit register or as
two independent 8 – bit registers.
DPTR used to hold the address of external data memory. This is the only register
used to access data from external data memory.

Bit 15 bit 14 bit 13 bit12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit2 bit 1 bit 0

Data pointer high (DPH) Data pointer low (DPL)

Bit 15 bit 14 bit 13 bit12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit2
bit 1 bit 0

DPH
DPL
ACCUMULATOR (A REGISTER): It is an 8 bit register used for many operations
including arithmetic and Boolean bit manipulations. This is also used for all data
transfers between 8051 and any external memory. It can also be used as general
purpose register, the result obtained during arithmetic and logical operations are
stored in accumulator.

bit 7 bit 6 bit 5 bit 4 bit 3 bit2 bit 1 bit 0

0 0 0 0 0 0 0 0
ACCUMULATOR (A REGISTER)
REGISTER B: It is an 8 bit register specially used for direct multiplication and
division operation with Accumulator. Both A and B registers are called as math
registers in 8051 family. It can also be used as a general purpose register.
During multiplication lower nibble is stored in A register and higher
nibble is stored in B register, and during division quotient is stored in A register and
remainder is stored in B register.

bit 7 bit 6 bit 5 bit 4 bit 3 bit2 bit 1 bit 0

0 0 0 0 0 0 0 0
B REGISTER
PROGRAM COUNTER (PC): It is a 16 bit register, which holds the address of the
next instruction to be executed. It is also called as instruction pointer (IP) and it is
not directly accessible to the programmer. PC automatically incremented after
every instruction is executed.
PROGRAM STATUS WORD (PSW) : The program status word (PSW) register is an
8 bit register. It is also referred to as the flag register. Although the PSW register is 8
bit wide, only 6 bits of it are used by the 8051. The two unused bits are user definable
flags. Four of the flags are called conditional flags, meaning that they indicate some
conditions that result after an instruction executed. These four are CY (carry), AC
(auxiliary carry), P (parity) and OV (over flow).

PSW.7 PSW.6 PSW.5 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0

CY AC F0 RS1 RS0 OV ---- P

CARRY FLAG (CY): This flag is set whenever there is a carry out from the D7 bit. This
flag bit is affected after an 8 bit addition or subtraction.
AUXILARY CARRY (AC): If there is a carry from d3 to d4 during an ADD or SUB
operation, this bit is set otherwise, it is cleared. This flag is used by instruction that
perform BCD (binary coded decimal) operation.

PARITY FLAG (P): The parity flag reflects the number of 1s in the A (accumulator)
register only. If the A register contains an odd number of 1s, then p=1, if the A
register contains even number of 1s, then p=0.

OVERFLOW (OV): Overflow occurs when the result of an arithmetic operation is


larger than 255 and cannot be stored in one register. Overflow condition causes the
OV bit to be set 1 otherwise it will be cleared 0.

RS1 AND RS0: These Two Bits are used to select one of four register banks of data
memory, by selecting and clearing these bits

F0: This is general purpose register available for user (user definable flag).

EXAMPLE: 1 56H 01010110

95H 10010101

EBH 11101011
In this calculation, CY=0 since there is no carry beyond d7
AC=0 since there is no carry from the D3 to D4
P=0 since the accumulator has an even number of bits.
EXAMPLE: 2 9CH 10011100

64H 01100100
100 00000000
In this calculation, CY=1 since there is carry beyond d7
AC=1 since there is carry from the D3 to D4
P=0 since the accumulator has an even number of bits
EXAMPLE: 3 BFH 10111111

1BH 00011011

DA 11011010

In this calculation, CY=0 since there is no carry beyond D7


AC=1 since there is carry from the D3 to D4
P=1 since the accumulator has an odd number of bits
DATA TYPES: The 8051 microcontroller has only one data type. It is 8 bits, and the size
of each register is also 8 bit. It is the job of the programmer to break down data larger
than 8 bits to be processed by the CPU.

DB (DEFINE BYTE): The DB directive is the most widely used data directive in the
assembler. It is used to define the 8 bits data. When DB is used to define data, the
numbers can be in decimal, binary, hex, or ASCII formats. For decimal, the “D” after the
decimal number is optional, but using “B” (binary) and “H” (hexadecimal) is required.
To indicate ASCII, simply place the characters in quotation marks ‘like this’.
Following are some DB examples.
DATA 1: DB 28 ; DECIMAL

DATA 2: DB 00110101B ; BINARY

DATA 3: DB 39H ; HEX

DATA4: DB”1234” ; ASCII NUMBERS

DATA 5: DB “ADITYA” ; ASCII CHARACTER.

DIRECTIVES :
ORG (ORIGIN): The ORG directive is used to indicate the beginning of the address.
The number that comes after ORG can be either in hex of in decimal. If the number
is not followed by H, it is decimal and the assembler will convert it to hex.

EQU (EQUATE): This is used to define a constant without occupying a memory


location. The EQU directive does not set aside storage for a data item but
associates a constant value with a data label so that when the label appears in the
program; its constant value will be substituted for the label.
COUNT EQU 25
MOV R3, #COUNT

END: END directive indicates to the assembler the end of the source file. The END
directive is the last line of an 8051 program, meaning that in the source code
anything after the END directive is ignored.

STACK AND STACK POINTER: 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 science there are only a limited number of registers. If
the stack is a section of RAM. There must be register inside the CPU to point to it.
The register used to access the stack is called the SP (stack pointer) register. The
stack pointer in the 8051 is only 8 bit wide, which means that it can take value of
00 to FFH.
When the 8051 powered up, the SP register contains value 07. This
means that RAM location 08 is the first location used for the stack by the 8051. The
storing of CPU register in the stack is called PUSH, and pulling back into CPU
register is called POP.
PUSHING ONTO THE STACK: In the 8051 the stack pointer (SP) points to the last
used location of the stack. As we push data onto the stack, the stack pointer (SP) is
incremented by one. Notice that for every byte of data saved on the stack SP is
incremented only once.
MOV R6, #25H
MOV R1, #12H
MOV R4, #0F3H
PUSH 6
PUSH 1
PUSH 4

After PUSH 6 After PUSH 1 After PUSH 4

0A 0A 0A 0A
0B 0B 0B 0B F3
O9 O9 O9 12 O9 12
O8 O8 25 O8 25 O8 25

SP =07 SP = 08 SP = 09 SP = 0A

POPPING FROM
register is the opposite process of pushing. With every POP, the top byte of
the stack is copied to the register specified by the instruction and the stack
pointer is decremented once.
POP 3 pop stack into R3
POP 5 pop stack into R5
POP 2 pop stack into R2

After POP 3 after POP 5 after POP 2


0B 54 0B 0B 0B
0A F9 0A F9 0A 0A
09 76 O9 76 O9 76 O9
08 6C O8 6C O8 6C O8 6C

SP 0B SP =0A SP = 09 SP =08

You might also like