SlideShare una empresa de Scribd logo
1 de 25
04/25/14 DPD 1
8051 Addressing Modes
04/25/14 DPD 2
Introduction
• Immediate Addressing
• Register Addressing
• Direct Addressing
• Register Indirect Addressing
• Indexed Addressing
04/25/14 DPD 3
Immediate Addressing
• MOV A, #25H
• MOV R4, #62
• MOV B, #40H
• MOV DTPR, #2550H
Same as
– MOV DPL, #50H
– MOV DPH, #25H
04/25/14 DPD 4
Register Addressing
• MOV A, R0
• MOV R2, A
• ADD A, R5
• ADD A, R7
• MOV R6, A
• MOV R4, R7 – invalid
• MOV DTPR, A – error
• MOV R7, DPL – valid
• MOV R6, DPH – valid
04/25/14 DPD 5
Direct Addressing
• MOV R0, 40H
• MOV 56H, A
• MOV R4, 7FH
• MOV R2, #5
• MOV A, 2
• MOV B, 2
• MOV 7, 2
• MOV A, 4
• MOV A, R4
• MOV A, 7
• MOV A, R7
04/25/14 DPD 6
SFR registers and their
addressing
• SFR – special function
register
• A, B, PSW, DPTR can
be addresses by
– Names
– Addresses
• A – E0H
• B – F0H
• MOV 0E0H, #55H
• MOV A, #55H
• MOV 0F0H, #25H
• MOV B, #25H
• MOV P1, A
• MOV 90H, A
04/25/14 DPD 7
SFR …contd.
• SFR have addresses
between 80H and FFH
• 00 to 7FH are addresses of
RAM memory inside 8051
• Not all address spaces of
80 to FF is used by the
SFR.
• Unused locations are
reserved and must not be
used by the 8051
programmer.
FFH
F0 – B register
E0 – Accumulator
D0 – PSW
B0 – Port 3
A0 – Port 2
90 – Port 1
83 – DPH
82 – DPL
81 – SP
80H 80 – Port 0
04/25/14 DPD 8
Stack and direct addressing
• PUSH A – invalid
• PUSH 0E0H – valid
• PUSH 05
• PUSH 06
• PUSH 0E0H
• PUSH 0F0H
• POP 02
• POP 03
04/25/14 DPD 9
Register Indirect Addressing
• A register is used as a
pointer to the data
• Only R0 and R1 are
used for this purpose
• Must be preceded by
‘@’ sign
• 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
04/25/14 DPD 10
Advantage of register indirect
addressing• Make accessing data
dynamic rather than static
MOV A, #55H
MOV 40H, A
MOV 41H, A
MOV 42H, A
MOV 43H, A
MOV 44H, A
MOV A, #55H
MOV R0, #40H
MOV @R0, A
INC R0
MOV @R0, A
INC R0
MOV @R0, A
INC R0
MOV @R0, A
INC R0
MOV @R0, A
MOV A, #55H
MOV R0, #40H
MOV R2, #05
AGAIN: MOV @R0, A
INC R0
DJNZ R2, AGAIN
• Looping is not possible in
direct addressing
04/25/14 DPD 11
Limitation of register indirect
addressing
• Only R0 and R1 can be used for this
purpose
• They 8 bit wide
• Use is limited to internal RAM (30H –
7FH)
• To access external RAM or on-chip ROM
we need 16-bit pointer
– DPTR is used in this case
04/25/14 DPD 12
Indexed addressing mode and
On-chip ROM access
• Used in accessing data elements of LUT
entries located in the program ROM space
of the 8051
• MOVC A, @A+DPTR
– C means code
• Contents of A is added to the 16-bit register
DPTR to form the 16-bit address of the
needed data
04/25/14 DPD 13
Example
• Assume that the word ‘USA’ is burned into
ROM location stating 200H, and that the
program is burned into location stating at 0.
• Analyze how the program works and state
where ‘USA’ is stored after this program is
run.
04/25/14 DPD 14
Solution
ORG 0000H
MOV DPTR, #200H
CLR A
MOVC A, @A+DPTR
MOV R0, A
INC DPTR
CLR A
MOVC A, @A+DPTR
MOV R1, A
INC DPTR
CLR A
MOVC A, @A+DPTR
MOV R2, A
HERE: SJMP HERE
ORG 200H
MYDATA: DB “USA”
END
04/25/14 DPD 15
Analysis
• ROM location 200H – 202H have the following
content
– 200 = (‘U’)
– 201 = (‘S’)
– 202 = (‘A’)
• Start with DPTR = 200H, and A = 0
• MOVC A, @A+DPTR → moves the content of
ROM location 200H (200H + 0 = 200H) to
register A
• Register A contains 55H, the ASCII value for ‘U’
• This is moved to R0
• Next DPTR is incremented to make DPTR = 201H
04/25/14 DPD 16
Example
• Assuming that ROM space starting at 250H
contains ‘India’
• Write a program to transfer the bytes into
RAM locations stating at 40H
04/25/14 DPD 17
Solution
ORG 0000
MOV DPTR, #MYDATA
MOV R0, #40H
MOV R2, #5
BACK: CLR A
MOVC A, @A+DPTR
MOV @R0, A
INC DPTR
INC R0
DJNZ R2, BACK
HERE: SJMP HERE
ORG 250H
MYDATA: DB “India”
END
04/25/14 DPD 18
Look-up table and MOVC
ORG 0
MOV DPTR, #300H
MOV A, #0FFH
MOV P1, A
BACK: MOV A, P1
MOVC A, @A+DPTR
MOV P2, A
SJMP BACK
• Write a program to the x
value from P1 and send x2
to P2 continuously
ORG 300H
XSQR_TABLE:
DB 0, 1, 4, 9, 16, 25, 36,
49, 64, 81
END
300 = 00H 303 = 09H
301 = 01H 304 = 10H
302 = 04H 305 = 19H
04/25/14 DPD 19
Accessing RAM locations 30 –
7FH as scratch pad
• Write a program to
toggle P1 a total of
200 times
• Use RAM location
32H to hold your
counter value instead
of registers R0 – R7
MOV P1, #55H
MOV 32H, #200
LOOP: CPL P1
ACALL DELAY
DJNZ 32H, LOOP
04/25/14 DPD 20
Bit-addressable RAM
• 16 bytes are bit-
addressable
• 20H – 2FH
• Provides 16 x 8 = 128 bits
• Addressed as 0 to 127 or
00H to 7FH
• 20H – 2FH RAM location
– Bit addressable
– Byte addressable
SETB 42H ;set bit 42H to 1
CLR 67H ;clear bit 67
CLR 0FH ;clear bit 0F
SETB 05
04/25/14 DPD 21
Single bit instruction
SETB bit bit =1
CLR bit bit = 0
CPL bit bit = NOT bit
JB bit, target Jump to target if bit = 1
JNB bit, target Jump to target if bit = 0
JBC bit, target Jump to target if bit = 1, clear bit
04/25/14 DPD 22
I/O port bit addresses
SETB 86H ;set bit P0.6
CLR 87H ;clear bit P0.7
04/25/14 DPD 23
Example
• Write a program to save Acc in R7 of Bank 2
CLR PSW.3
SETB PSW.4
MOV R7, A
• How to check overflow?
JB PSW.2, TARGET
• Check if RAM location 37H contains an even
value. If so, send it to P2, else make it even and
send it to P2.
MOV A, 37H
JNB ACC.0, YES
INC A
YES: MOV P2, A
04/25/14 DPD 24
Bit Directive
LED BIT P1.7
HERE: CPL LED
LCALL DELAY
SJMP HERE
SW BIT P1.7
LED BIT P2.0
HERE: MOV C, SW
MOV LED, C
SJMP HERE
04/25/14 DPD 25
Using EQU directive
• A switch is connected
to pin P1.7
• Write a program to
check that status of the
switch and make the
following decision
– If SW = 0, send “No”
to P2
– If SW = 1, send “Yes”
to P2
SW EQU P1.7
MYDATA EQU P2
HERE: MOV C, SW
JC OVER
MOV MYDATA, #’N’
MOV MYDATA, #’O’
SJMP HERE
OVER: MOV MYDATA, #’Y’
MOV MYDATA, #’Y’
MOV MYDATA, #’Y’
SJMP HERE
END

Más contenido relacionado

La actualidad más candente

Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051
Jay Patel
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller Notes
Dr.YNM
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
jemimajerome
 
Memory organization of 8051
Memory organization of 8051Memory organization of 8051
Memory organization of 8051
Muthu Manickam
 

La actualidad más candente (20)

ARM Architecture
ARM ArchitectureARM Architecture
ARM Architecture
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
 
DAA AND DAS
DAA AND DASDAA AND DAS
DAA AND DAS
 
8086 signals
8086 signals8086 signals
8086 signals
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
 
The 8051 microcontroller
The 8051 microcontrollerThe 8051 microcontroller
The 8051 microcontroller
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
Unit 5
Unit 5Unit 5
Unit 5
 
Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051
 
8051 serial communication-UART
8051 serial communication-UART8051 serial communication-UART
8051 serial communication-UART
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller Notes
 
Arm modes
Arm modesArm modes
Arm modes
 
8085 Interfacing with I/O Devices or Memory
8085 Interfacing with I/O Devices or Memory8085 Interfacing with I/O Devices or Memory
8085 Interfacing with I/O Devices or Memory
 
MOS transistor 13
MOS transistor 13MOS transistor 13
MOS transistor 13
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction set
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
 
Memory organization of 8051
Memory organization of 8051Memory organization of 8051
Memory organization of 8051
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction Set
 

Destacado

8051-mazidi-solution
8051-mazidi-solution8051-mazidi-solution
8051-mazidi-solution
ZunAib Ali
 
8051 serial communication
8051 serial communication8051 serial communication
8051 serial communication
canh phan
 
8051 microcontroller features
8051 microcontroller features8051 microcontroller features
8051 microcontroller features
Tech_MX
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))
Ganesh Ram
 

Destacado (20)

Addressing mode of 8051
Addressing mode of 8051Addressing mode of 8051
Addressing mode of 8051
 
Addressing Modes
Addressing ModesAddressing Modes
Addressing Modes
 
8051-mazidi-solution
8051-mazidi-solution8051-mazidi-solution
8051-mazidi-solution
 
8051 Addressing modes
8051 Addressing modes8051 Addressing modes
8051 Addressing modes
 
8051 serial communication
8051 serial communication8051 serial communication
8051 serial communication
 
Serial1
Serial1Serial1
Serial1
 
Class8
Class8Class8
Class8
 
8051 ch9
8051 ch98051 ch9
8051 ch9
 
Addressing modes of 8051
Addressing modes  of 8051Addressing modes  of 8051
Addressing modes of 8051
 
8051 addressing modes
8051 addressing modes8051 addressing modes
8051 addressing modes
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontroller
 
8051 microcontroller by K. Vijay Kumar
8051 microcontroller by K. Vijay Kumar8051 microcontroller by K. Vijay Kumar
8051 microcontroller by K. Vijay Kumar
 
8051 architecture
8051 architecture8051 architecture
8051 architecture
 
8051 Presentation
8051 Presentation8051 Presentation
8051 Presentation
 
8051 microcontroller features
8051 microcontroller features8051 microcontroller features
8051 microcontroller features
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))
 
Question paper with solution the 8051 microcontroller based embedded systems...
Question paper with solution  the 8051 microcontroller based embedded systems...Question paper with solution  the 8051 microcontroller based embedded systems...
Question paper with solution the 8051 microcontroller based embedded systems...
 
Green house effect
Green house effectGreen house effect
Green house effect
 
Gate life sciences 2009
Gate life sciences 2009Gate life sciences 2009
Gate life sciences 2009
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
 

Similar a 8051 addressing modes

432_17EC563_8051-microcontroller-moving-data_notes.pdf
432_17EC563_8051-microcontroller-moving-data_notes.pdf432_17EC563_8051-microcontroller-moving-data_notes.pdf
432_17EC563_8051-microcontroller-moving-data_notes.pdf
ShreeKrishnaTarai
 
Addressing Modes of 8051.pptx
Addressing Modes of 8051.pptxAddressing Modes of 8051.pptx
Addressing Modes of 8051.pptx
TumkurInfomedia
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent
vijaydeepakg
 
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp011347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
bvenkanna
 

Similar a 8051 addressing modes (20)

Microcontroller 8051 soft
Microcontroller 8051  softMicrocontroller 8051  soft
Microcontroller 8051 soft
 
MICROCONTROLLERS-module2 (7).pptx
MICROCONTROLLERS-module2 (7).pptxMICROCONTROLLERS-module2 (7).pptx
MICROCONTROLLERS-module2 (7).pptx
 
Embedded Systems Training & Live Projects @Technogroovy Systems India Pvt Ltd
Embedded Systems Training & Live Projects @Technogroovy Systems India Pvt Ltd Embedded Systems Training & Live Projects @Technogroovy Systems India Pvt Ltd
Embedded Systems Training & Live Projects @Technogroovy Systems India Pvt Ltd
 
Microcontroller 8051- soft.ppt
Microcontroller 8051- soft.pptMicrocontroller 8051- soft.ppt
Microcontroller 8051- soft.ppt
 
8051 addressing modes
8051 addressing modes8051 addressing modes
8051 addressing modes
 
8051 instruction_set.ppt
8051 instruction_set.ppt8051 instruction_set.ppt
8051 instruction_set.ppt
 
432_17EC563_8051-microcontroller-moving-data_notes.pdf
432_17EC563_8051-microcontroller-moving-data_notes.pdf432_17EC563_8051-microcontroller-moving-data_notes.pdf
432_17EC563_8051-microcontroller-moving-data_notes.pdf
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
mup
mupmup
mup
 
addressing-mode-of-8051.pdf
addressing-mode-of-8051.pdfaddressing-mode-of-8051.pdf
addressing-mode-of-8051.pdf
 
Addressing Modes of 8051.pptx
Addressing Modes of 8051.pptxAddressing Modes of 8051.pptx
Addressing Modes of 8051.pptx
 
5 addressing modes
5 addressing modes5 addressing modes
5 addressing modes
 
New text document
New text documentNew text document
New text document
 
Winter training,Readymade Projects,Buy Projects,Corporate Training
Winter training,Readymade Projects,Buy Projects,Corporate TrainingWinter training,Readymade Projects,Buy Projects,Corporate Training
Winter training,Readymade Projects,Buy Projects,Corporate Training
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent
 
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp011347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
 
instructions set of 8051.pdf
instructions set of 8051.pdfinstructions set of 8051.pdf
instructions set of 8051.pdf
 
13229286.ppt
13229286.ppt13229286.ppt
13229286.ppt
 
8085-instruction.ppt
8085-instruction.ppt8085-instruction.ppt
8085-instruction.ppt
 

Último

DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 

8051 addressing modes

  • 1. 04/25/14 DPD 1 8051 Addressing Modes
  • 2. 04/25/14 DPD 2 Introduction • Immediate Addressing • Register Addressing • Direct Addressing • Register Indirect Addressing • Indexed Addressing
  • 3. 04/25/14 DPD 3 Immediate Addressing • MOV A, #25H • MOV R4, #62 • MOV B, #40H • MOV DTPR, #2550H Same as – MOV DPL, #50H – MOV DPH, #25H
  • 4. 04/25/14 DPD 4 Register Addressing • MOV A, R0 • MOV R2, A • ADD A, R5 • ADD A, R7 • MOV R6, A • MOV R4, R7 – invalid • MOV DTPR, A – error • MOV R7, DPL – valid • MOV R6, DPH – valid
  • 5. 04/25/14 DPD 5 Direct Addressing • MOV R0, 40H • MOV 56H, A • MOV R4, 7FH • MOV R2, #5 • MOV A, 2 • MOV B, 2 • MOV 7, 2 • MOV A, 4 • MOV A, R4 • MOV A, 7 • MOV A, R7
  • 6. 04/25/14 DPD 6 SFR registers and their addressing • SFR – special function register • A, B, PSW, DPTR can be addresses by – Names – Addresses • A – E0H • B – F0H • MOV 0E0H, #55H • MOV A, #55H • MOV 0F0H, #25H • MOV B, #25H • MOV P1, A • MOV 90H, A
  • 7. 04/25/14 DPD 7 SFR …contd. • SFR have addresses between 80H and FFH • 00 to 7FH are addresses of RAM memory inside 8051 • Not all address spaces of 80 to FF is used by the SFR. • Unused locations are reserved and must not be used by the 8051 programmer. FFH F0 – B register E0 – Accumulator D0 – PSW B0 – Port 3 A0 – Port 2 90 – Port 1 83 – DPH 82 – DPL 81 – SP 80H 80 – Port 0
  • 8. 04/25/14 DPD 8 Stack and direct addressing • PUSH A – invalid • PUSH 0E0H – valid • PUSH 05 • PUSH 06 • PUSH 0E0H • PUSH 0F0H • POP 02 • POP 03
  • 9. 04/25/14 DPD 9 Register Indirect Addressing • A register is used as a pointer to the data • Only R0 and R1 are used for this purpose • Must be preceded by ‘@’ sign • 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
  • 10. 04/25/14 DPD 10 Advantage of register indirect addressing• Make accessing data dynamic rather than static MOV A, #55H MOV 40H, A MOV 41H, A MOV 42H, A MOV 43H, A MOV 44H, A MOV A, #55H MOV R0, #40H MOV @R0, A INC R0 MOV @R0, A INC R0 MOV @R0, A INC R0 MOV @R0, A INC R0 MOV @R0, A MOV A, #55H MOV R0, #40H MOV R2, #05 AGAIN: MOV @R0, A INC R0 DJNZ R2, AGAIN • Looping is not possible in direct addressing
  • 11. 04/25/14 DPD 11 Limitation of register indirect addressing • Only R0 and R1 can be used for this purpose • They 8 bit wide • Use is limited to internal RAM (30H – 7FH) • To access external RAM or on-chip ROM we need 16-bit pointer – DPTR is used in this case
  • 12. 04/25/14 DPD 12 Indexed addressing mode and On-chip ROM access • Used in accessing data elements of LUT entries located in the program ROM space of the 8051 • MOVC A, @A+DPTR – C means code • Contents of A is added to the 16-bit register DPTR to form the 16-bit address of the needed data
  • 13. 04/25/14 DPD 13 Example • Assume that the word ‘USA’ is burned into ROM location stating 200H, and that the program is burned into location stating at 0. • Analyze how the program works and state where ‘USA’ is stored after this program is run.
  • 14. 04/25/14 DPD 14 Solution ORG 0000H MOV DPTR, #200H CLR A MOVC A, @A+DPTR MOV R0, A INC DPTR CLR A MOVC A, @A+DPTR MOV R1, A INC DPTR CLR A MOVC A, @A+DPTR MOV R2, A HERE: SJMP HERE ORG 200H MYDATA: DB “USA” END
  • 15. 04/25/14 DPD 15 Analysis • ROM location 200H – 202H have the following content – 200 = (‘U’) – 201 = (‘S’) – 202 = (‘A’) • Start with DPTR = 200H, and A = 0 • MOVC A, @A+DPTR → moves the content of ROM location 200H (200H + 0 = 200H) to register A • Register A contains 55H, the ASCII value for ‘U’ • This is moved to R0 • Next DPTR is incremented to make DPTR = 201H
  • 16. 04/25/14 DPD 16 Example • Assuming that ROM space starting at 250H contains ‘India’ • Write a program to transfer the bytes into RAM locations stating at 40H
  • 17. 04/25/14 DPD 17 Solution ORG 0000 MOV DPTR, #MYDATA MOV R0, #40H MOV R2, #5 BACK: CLR A MOVC A, @A+DPTR MOV @R0, A INC DPTR INC R0 DJNZ R2, BACK HERE: SJMP HERE ORG 250H MYDATA: DB “India” END
  • 18. 04/25/14 DPD 18 Look-up table and MOVC ORG 0 MOV DPTR, #300H MOV A, #0FFH MOV P1, A BACK: MOV A, P1 MOVC A, @A+DPTR MOV P2, A SJMP BACK • Write a program to the x value from P1 and send x2 to P2 continuously ORG 300H XSQR_TABLE: DB 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 END 300 = 00H 303 = 09H 301 = 01H 304 = 10H 302 = 04H 305 = 19H
  • 19. 04/25/14 DPD 19 Accessing RAM locations 30 – 7FH as scratch pad • Write a program to toggle P1 a total of 200 times • Use RAM location 32H to hold your counter value instead of registers R0 – R7 MOV P1, #55H MOV 32H, #200 LOOP: CPL P1 ACALL DELAY DJNZ 32H, LOOP
  • 20. 04/25/14 DPD 20 Bit-addressable RAM • 16 bytes are bit- addressable • 20H – 2FH • Provides 16 x 8 = 128 bits • Addressed as 0 to 127 or 00H to 7FH • 20H – 2FH RAM location – Bit addressable – Byte addressable SETB 42H ;set bit 42H to 1 CLR 67H ;clear bit 67 CLR 0FH ;clear bit 0F SETB 05
  • 21. 04/25/14 DPD 21 Single bit instruction SETB bit bit =1 CLR bit bit = 0 CPL bit bit = NOT bit JB bit, target Jump to target if bit = 1 JNB bit, target Jump to target if bit = 0 JBC bit, target Jump to target if bit = 1, clear bit
  • 22. 04/25/14 DPD 22 I/O port bit addresses SETB 86H ;set bit P0.6 CLR 87H ;clear bit P0.7
  • 23. 04/25/14 DPD 23 Example • Write a program to save Acc in R7 of Bank 2 CLR PSW.3 SETB PSW.4 MOV R7, A • How to check overflow? JB PSW.2, TARGET • Check if RAM location 37H contains an even value. If so, send it to P2, else make it even and send it to P2. MOV A, 37H JNB ACC.0, YES INC A YES: MOV P2, A
  • 24. 04/25/14 DPD 24 Bit Directive LED BIT P1.7 HERE: CPL LED LCALL DELAY SJMP HERE SW BIT P1.7 LED BIT P2.0 HERE: MOV C, SW MOV LED, C SJMP HERE
  • 25. 04/25/14 DPD 25 Using EQU directive • A switch is connected to pin P1.7 • Write a program to check that status of the switch and make the following decision – If SW = 0, send “No” to P2 – If SW = 1, send “Yes” to P2 SW EQU P1.7 MYDATA EQU P2 HERE: MOV C, SW JC OVER MOV MYDATA, #’N’ MOV MYDATA, #’O’ SJMP HERE OVER: MOV MYDATA, #’Y’ MOV MYDATA, #’Y’ MOV MYDATA, #’Y’ SJMP HERE END