The 8051 Microcontroller and Embedded Systems: 8051 Addressing Modes
The 8051 Microcontroller and Embedded Systems: 8051 Addressing Modes
Embedded Systems
CHAPTER 5
8051 ADDRESSING
MODES
OBJECTIVES
Addressing Modes
(1) immediate
(2) register
(3) direct
(4) register indirect
(5) indexed
SFR
Table 51
8051 Special Function Register
(SFR) Addresses
MOVC A, @ A+DPTR
RAM
Figure 51
16 Bytes of Internal RAM. Note:
They are both bit- and byte-accessible.
Table 52
RAM
Single-Bit Instructions
Figure 52
memory map
Table 53
bit-addressability
Figure 53
Types Of Instructions
1.
2.
3.
4.
5.
Data
DESCRIPTION
BYTES
MOV
A,Rn
(A)
(Rn)
MOV
A,Rx
(A)
(Rx)
MOV
A,@Ri
(A)
(Ri)
1
PUNJAB EDUSAT SOCIETY
A,#X
(A)
Data
MOV
Rn,A
(Rn)
(A)
MOV
Rn, Rx
(Rn)
(Rx)
Rn, #X
(Rn)
Data
MOV
Rx, A
(Rx)
(A)
MOV
Rx, Rn
(Rx)
(Rn)
Rx, Ry
(RX)
(Ry)
MOV
Rx, @ Ri
(Rx)
(Ri)
MOV
Rx, # X
(Rx)
Data
@ Ri, A
(Ri)
(A)
MOV
@ Ri, Rx
(Ri)
(Rx)
MOV
@ Ri, #X
(Ri)
Data
DPTR, #X
MOVC
A@
A+DPTR
MOVC
A@
(DPTR)
Data
(A)
(A+DPTR)
(A)
(A+PC)
A+PC
PUNJAB EDUSAT SOCIETY
MOVX
A,@ Ri
MOVX
A, @
(A)
@Ri, A
(Ri)
(Ri)
(DPTR)
DPTR
MOVX
(A)
1
PUNJAB EDUSAT SOCIETY
@
DPTR, A
(DPTR)
PUSH
POP
(A)
Rx
Push directly
addressed Rx register on stack
Rx
(A)
(Rx)
A, Rn
(A)
(Rn)
XCH
A, Rx
(A)
(Rx)
XCH
A, @Ri
(A)
(Ri)
Exchange 4 lower
1
bits in accumulator with indirectly
addressed register
Arithmetic Instructions
These
Arithmetic Instructions
MNEMONICS
DESCRIPTION
BYTE
ADD
A, Rn
A = A + Rn
ADD
A, Rx
A = A + Rx
AAD
A, @ Ri
A = A+ Ri
1
PUNJAB EDUSAT SOCIETY
Arithmetic Instructions
ADD
A, # X
A = A + Byte
ADDC
A, Rn
A = A + Rn + C
ADDC
A , Rx
A = A + Rx + C
Arithmetic Instructions
ADDC
A, @ Ri
A = A + Ri + C
ADDC
A, # X
A = A + Byte + C
SUBB
A, Rn
A = A Rn 1
Arithmetic Instructions
SUBB
A, Rx
A = A Rx 1
SUBB
A, @ Ri
A = A Ri 1
SUBB
A, # X
A = A Byte 1
Arithmetic Instructions
INC
A= A+ 1
INC
Rn
Rn = Rn + 1
INC
Rx
Rx = Rx + 1
Arithmetic Instructions
INC
@ Ri
Ri = Ri + 1
DEC
A= A 1
DEC
Rn
Rn = Rn 1
Arithmetic Instructions
DEC
Rx
Rx = Rx 1
DEC
@ Ri
Ri = Ri 1
DPTR = DPTR + 1
INC
DPTR
Arithmetic Instructions
MUL AB
B:A = A * B
DIV
A = [A/B]
AB
DA A
Decimal adjustment of
1
accumulator according to BCD code
Logical Instructions
These
After
Logical Instructions
MNEMONIC
DESCRIPTION
ANL A,
Rn
(A)
(A) ^ (Rn)
ANL A,
Rx
(A)
(A) ^ (Rx)
(A)
(A) ^ (Ri)
ANL A,@
Ri
BYTE
Logical Instructions
ANL A,
#X
ANL
Rx, A
(Rx)
(A) ^ (Rx)
ANL
Rx,# X
2
2
3
Logical Instructions
ORL A,
Rn
(A)
(A) + (Rn)
ORL A,
Rx
(A)
(A) + (Rx)
ORL A,
@ Ri
(A)
(A) + (Ri)
Logical Instructions
ORL
Rx, A
ORL
Rx,# X
XORL A,
Rn
Logical exclusive
OR operation between the contents of
accumulator and R register.
Logical Instructions
XORL A,
Rx
Logical exclusive OR
2
operation between the contents of the
accumulator and directly addressed register
Rx.
XORL A,@ Ri
Logical exclusive OR
1
operation between the
contents of the accumulator and directly
addressed register.
PUNJAB EDUSAT SOCIETY
Logical Instructions
XORL A,
#X
Logical exclusive OR
2
operation between the contents of
accumulator and the given 8 bit data.
XORL Rx, A
Logical exclusive OR
2
operation between the contents of the
accumulator and directly addressed register
Rx.
PUNJAB EDUSAT SOCIETY
Logical Instructions
XORL
Rx, # X
Logical exclusive OR 3
operation between the contents of the
directly addressed register Rx and the given
8 bit data.
CLR A
(A) 0
1
CPL A
(A)
(/A)
1
PUNJAB EDUSAT SOCIETY
Logical Instructions
SWAP
RL A
RLC
(A3-0)
(A7-4)
(An + 1)
(A0)
(An + 1)
(A0)
(C)
(An)
(A7)
(An)
(C)
(A7)
1
1
Logical Instructions
RR
RRC
(An)
(A7)
(An + 1)
(A0)
(An)
(A7)
(C)
(An + 1)
(C)
(A0)
The
CLR
bit
SETB
DESCRIPTION
(C=0)
BYTE
1
1
PUNJAB EDUSAT SOCIETY
bit
Set directly
2
addressed bit
CPL
(1 = 0, 0 = 1)
CPL
bit
Complement directly
addressed bit
1
2
C, bit
Logical AND operation 2
between Carry bit and directly addressed
bit.
ANL
C,/bit
Logical AND operation
between Carry bit and inverted directly
addressed bit.
C, bit
Logical OR operation
2
between Carry bit and directly addressed
bit.
ORL
C,/bit
Logical OR operation
between Carry bit and inverted directly
addressed bit.
C, bit
Move directly addressed 2
bit to carry bit.
MOV
bit, C
Move Carry bit to directly 2
addressed bit.
Some
adr11
DESCRIPTION
(PC)
(SP)
((SP))
(SP)
((SP))
(PC) + 2
(SP) + 1
(PC7 0)
(SP) + 1
(PC15-8)
BYTE
2
adr16
(PC)
(SP)
((SP))
(SP)
((SP))
(PC)
(PC) + 3
(SP) + 1
(PC7-0)
(SP) + 1
(PC15-8)
addr15-0
(PC15-8)
(SP)
(PC7-0)
(SP)
((SP))
(SP) 1
((SP))
(SP) - 1
AJMP
addr11
(PC15-8)
(SP)
(PC7-0)
(SP)
((SP))
(SP) 1
((SP))
(SP) 1
(PC)
(PC10-0)
(PC) + 2
1
page address
PUNJAB EDUSAT SOCIETY
addr16
SJMP
rel
(PC)
addr15-0
rel
JNC
rel
(PC)
(PC) + 2
IF ( C ) = 1
THEN (PC)
(PC) + rel
(PC) (PC) + 2
IF ( C) = 0
THEN (PC)
(PC) + rel
bit, rel
Jump if addressed
bit, rel
Jump if addressed
bit is set and clear it.
Short jump.
@A + DPTR (PC)
rel
(A) + (DPTR)
(PC) (PC) + 2
IF (A) = 0
THEN (PC) (PC) + rel
1
2
rel
(PC)
(PC) + 2
IF (A) = 0
THEN (PC)
(PC) + rel
CJNE
A, Rx, rel
Compare the contents 3
of acc. And directly addressed register Rx.
Jump if they are different. Short jump.
PUNJAB EDUSAT SOCIETY
A, #X, rel
(PC)
(PC) + 3
3
IF ( A) < > data
THEN (PC)
(PC) + relative
offset
IF (A) < data
THEN ( C )
1
ELSE ( C )
0
PUNJAB EDUSAT SOCIETY
@ RI, # x, rel
(PC)
(PC) + 3
3
IF (Rn) <> data
THEN (PC)
(PC) + relative
offset
IF (Rn) < data
THEN ( C )
1
ELSE ( C )
0
PUNJAB EDUSAT SOCIETY
Rn , rel
(PC) (PC) + 2
2
(Rn)
(Rn) - 1
IF (Rn) > 0 or (Rn) < 0
THEN (PC)
(PC) + rel
NOP
Rx, rel
(PC)
(Rx)
IF (Rx) >
THEN (PC)
(PC) + 2
3
(Rn) 1
0 or (Rx) < 0
(PC) + rel
No operation
Summary
Instruction
set.
Addressing modes.
Data transfer instruction.
Arithmetic instruction.
Logical instruction.
Logical operation on bits.
Next
Lecture
Proteus