2. 8051 Registers
D7 D6 D5 D4 D3 D2 D1 D0
DPTR
PC PC (Program counter)
DPH DPL
8 bit Registers of the 8051
8051 16 bit Registers
8 bit Registers
R6
R5
R4
R3
R2
R1
R0
B
A
R7
3. ADDRESSING MODES OF 8051
1. Immediate addressing
2. Register addressing
3. Direct addressing
4. Register indirect addressing
5. Indexed addressing
6. Relative addressing
7. Absolute addressing
8. Long addressing
9. Inherent addressing
10.Bit Inherent addressing
11. Bit Direct addressing
12. Stack addressing mode
4. Immediate Addressing Mode
MOV A, #25H ;load 25H into A
MOV R4, #62 ;load the decimal value 62 into R4
MOV B, #40H ;load 40H into B
MOV DPTR, #4521H ;DPTR=4521H
MOV DPTR, #2550H ;is the same as:
MOV DPL, #50H
MOV DPH, #25H
5. Register Addressing Mode
MOV A,R0 ;copy the contents of R0 into A
MOV R2,A ;copy the contents of A into R2
ADD A,R5 ;add the contents of R5 to contents of A
ADD A,R7 ;add the contents of R7 to contents of A
MOV R6,A ;save accumulator in R6
MOV DPTR,#25F5H
MOV R7,DPL
MOV R6,DPH
6. Direct Addressing Mode
MOV R0,40H ;save content of RAM location 40H in R0
MOV R4,7FH ;move contents of RAM location 7FH to R4
MOV A,4
MOV A,7
ADD A, 50
7. MOV A,2 ;is the same as
MOV A,R2 ;which means copy R2 into A
MOV A,0 ;is the same as
MOV A,R0 ;which means copy R0 into A
MOV R2,#5 ;R2=05
8. Register Indirect Addressing Mode
• Only R0, R1 &DPTR are the only registers that can be used
for pointers in register indirect addressing mode.
MOV A,@R0 ;move contents of RAM location whose
address is held by R0 into A
MOV @R1,B ;move contents of B into RAM location
whose address is held by R1
MOVX A,@DPTR ; copy the contents of external data memory
pointed by DPTR into the accumulator.
9. Indexed Addressing Mode
• It uses DPTR as a reference.
• 16 bits
MOVC A, @A+DPTR
MOVC A, @A+PC ; “C” means program
(code) space ROM
10. Relative addressing
It is used for short JMP(Jump) and short
Call(8-bit) instructions in 8051 use the relative
addressing.
In relative addressing, a new program address
is not directed specified.
It is specified as PC+offset gives the new
program address.
For Ex: 2000: JMP 20
11. Absolute Addressing
• The addressing mode is similar to that of relative
addressing expect the offset length.
• Here, the offset is 11-bit instead of 8-bit in case of
relative addressing.
• The 11-bit offset gives an address range of from
0000H to 07FFH.
For example: AJMP NEXT
ACALL SUB1
12. Long addressing
In long addressing mode (LJMP or LCALL) is
specified as entire new 16-bit address.
Since address is 16-bit, a jump or a call can be
made to a location within a 64-kbytes(0000-
FFFFH) code memory space.
For Example: LJMP 2000H
LCALL 3000H
14. Bit Inherent Addressing
• Bit inherent addressing works on any single
bit.
For example: 1.CLR C
2.CPL C
15. Bit Direct addressing
• The RAM address space from 20H to 2FH and
some Special Function Registers(SFRs) are bit
addressable.
For Ex: SETB 06H
CLR P1.2
16. Stack Addressing Mode
• It is subtype of direct addressing mode in which
stack instructions(PUSH and POP) are used.
• Instruction such as “PUSH A” is invalid. Here,
we have to specify the address of register A.
For example:
1. PUSH 04 ; Push R4 onto stack
2. PUSH 06 ; Push R6 onto stack
3. POP 02 ; Pop top of stack into R2
4. POP 0F0H ; Pop top of stack into register B