Professional Documents
Culture Documents
Addressing modes
And
Instructions set
Addressing Modes
The various ways of accessing data are called
addressing modes
The data could be in register, or in memory or be
provided as an immediate value
Immediate
Register
Direct
Indirect
Addressing Modes
So 8051 has lot of instructions for
movement of data
They are
MOV destination, source
PUSH source or POP destination
XCH destination, source
operation
MOV Rr,#n
copy 8 bit data to register Rr
Mov A,#n
copy 8 bit data to accumulator
Mov DPTR,#nn copy 16 bit data to DPTR
A,#65H
A,#A
R6,#65H
DPTR,#2343H
P1,#65H
Rn, A
A, Rn
DPL, R6
MOV
MOV
DPTR, A
Rm, Rn
;n=0,..,7
R0, 40H
56H, A
A, 4
6, 2
; MOV A, R4
; copy R2 to R6
; MOV R6,R2 is invalid !
0E0H, #66H
0F0H, R2
80H,A
; MOV A,#66H
; MOV B, R2
; MOV P1,A
MOV
A,@Ri
MOV
@R1,B
In other word, the content of register R0 or R1 is sources or target in MOV, ADD and SUBB
insructions.
Example:
Write a program to copy a block of 10 bytes from RAM location sterting at 37h to RAM
location starting at 59h.
Solution:
MOV R0,37h
MOV R1,59h
MOV R2,10
L1: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R2,L1
; source pointer
; dest pointer
; counter
MOV
A,@Ri ; move content of RAM loc.Where address is held by Ri into A
( i=0 or 1 )
MOV
@R1,B
In other word, the content of register R0 or R1 is sources or target in MOV, ADD and
SUBB insructions.
Example:
Write a program to copy a block of 10 bytes from RAM location sterting at 37h to
RAM location starting at 59h.
Solution:
MOV R0,37h ; source pointer
MOV R1,59h ; dest pointer
MOV R2,10 ; counter
L1: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R2,L1
7FH
Scratch pad RAM
30H
2FH
Bit-Addressable RAM
20H
1FH
18H
17H
10H
0FH
08H
07H
00H
Register Bank 3
Register Bank 2
Register Bank 1( Stack)
Register Bank 0
Example:
MOV
MOV
MOV
PUSH
PUSH
PUSH
R6,#25H
R1,#12H
R4,#0F3H
6
1
4
0BH
0BH
0BH
0BH
0AH
0AH
0AH
0AH
F3
09H
09H
09H
12
09H
12
08H
08H
08H
25
08H
25
Start SP=07H
25
SP=08H
SP=09H
SP=08H
Example:
Assuming that ROM space starting at 250h contains Hello., write a program to transfer the
bytes into RAM locations starting at 40h.
Solution:
ORG
0
MOV
DPTR,#MYDATA
MOV
R0,#40H
L1: CLR
A
MOVC
A,@A+DPTR
JZ
L2
MOV
@R0,A
INC
DPTR
INC
R0
SJMP
L1
L2: SJMP
L2
;------------------------------------ORG
250H
MYDATA:DB
Hello,0
END
Notice the NULL character ,0, as end of string and how we use the JZ instruction to
detect that.
Example:
Write a program to get the x value from P1 and send x 2 to P2, continuously .
Solution:
ORG
0
MOV DPTR, #TAB1
MOV A,#0FFH
MOV P1,A
L01:
MOV A,P1
MOVC A,@A+DPTR
MOV
P2,A
SJMP
L01
;---------------------------------------------------ORG
300H
TAB1: DB
0,1,4,9,16,25,36,49,64,81
END