SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.Prof. Swapnil V. Kaware
 
Serial communication in 8085
Serial communication in 8085Serial communication in 8085
Serial communication in 8085Nitin Ahire
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructionsRavi Anand
 
Address translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhuteAddress translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhuteAniket Bhute
 
23. serial and parallel data communication
23. serial and parallel data communication23. serial and parallel data communication
23. serial and parallel data communicationsandip das
 
History of microprocessors copy
History of microprocessors   copyHistory of microprocessors   copy
History of microprocessors copyyvonne katsande
 
UART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPTUART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPTSai_praneeth
 
8085 Architecture & Memory Interfacing1
8085 Architecture & Memory Interfacing18085 Architecture & Memory Interfacing1
8085 Architecture & Memory Interfacing1techbed
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingAnkur Mahajan
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / CountersPatricio Lima
 
8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessorjhcid
 
Addressing modes 8085
Addressing modes 8085Addressing modes 8085
Addressing modes 8085ShivamSood22
 
The 8051 microcontroller
The 8051 microcontrollerThe 8051 microcontroller
The 8051 microcontrollerPallaviHailkar
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architectureDominicHendry
 
Design options for digital systems
Design options for digital systemsDesign options for digital systems
Design options for digital systemsdennis gookyi
 
Memory intrface and addrs modes
Memory intrface and addrs modesMemory intrface and addrs modes
Memory intrface and addrs modesbalbirvirdi
 

What's hot (20)

Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.
 
Serial communication in 8085
Serial communication in 8085Serial communication in 8085
Serial communication in 8085
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructions
 
Address translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhuteAddress translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhute
 
23. serial and parallel data communication
23. serial and parallel data communication23. serial and parallel data communication
23. serial and parallel data communication
 
History of microprocessors copy
History of microprocessors   copyHistory of microprocessors   copy
History of microprocessors copy
 
UART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPTUART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPT
 
8085 Architecture & Memory Interfacing1
8085 Architecture & Memory Interfacing18085 Architecture & Memory Interfacing1
8085 Architecture & Memory Interfacing1
 
Microprocessors
MicroprocessorsMicroprocessors
Microprocessors
 
dual-port RAM (DPRAM)
dual-port RAM (DPRAM)dual-port RAM (DPRAM)
dual-port RAM (DPRAM)
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacing
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / Counters
 
8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
 
8255 presentaion.ppt
8255 presentaion.ppt8255 presentaion.ppt
8255 presentaion.ppt
 
Addressing modes 8085
Addressing modes 8085Addressing modes 8085
Addressing modes 8085
 
The 8051 microcontroller
The 8051 microcontrollerThe 8051 microcontroller
The 8051 microcontroller
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
 
Design options for digital systems
Design options for digital systemsDesign options for digital systems
Design options for digital systems
 
Memory intrface and addrs modes
Memory intrface and addrs modesMemory intrface and addrs modes
Memory intrface and addrs modes
 
SATA Protocol
SATA ProtocolSATA Protocol
SATA Protocol
 

Viewers also liked

Addressing mode of 8051
Addressing mode of 8051Addressing mode of 8051
Addressing mode of 8051Nitin Ahire
 
Addressing Modes
Addressing ModesAddressing Modes
Addressing ModesMayank Garg
 
8051-mazidi-solution
8051-mazidi-solution8051-mazidi-solution
8051-mazidi-solutionZunAib Ali
 
8051 serial communication
8051 serial communication8051 serial communication
8051 serial communicationcanh phan
 
Addressing modes of 8051
Addressing modes  of 8051Addressing modes  of 8051
Addressing modes of 8051Bharath Reddy
 
8051 addressing modes
8051 addressing modes8051 addressing modes
8051 addressing modessb108ec
 
8051 microcontroller by K. Vijay Kumar
8051 microcontroller by K. Vijay Kumar8051 microcontroller by K. Vijay Kumar
8051 microcontroller by K. Vijay KumarVijay Kumar
 
Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Jay Patel
 
8051 architecture
8051 architecture8051 architecture
8051 architecturesb108ec
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051SARITHA REDDY
 
8051 microcontroller features
8051 microcontroller features8051 microcontroller features
8051 microcontroller featuresTech_MX
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Ganesh Ram
 
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...manishpatel_79
 

Viewers also liked (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 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
 
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
 
Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051
 
8051 architecture
8051 architecture8051 architecture
8051 architecture
 
8051 Presentation
8051 Presentation8051 Presentation
8051 Presentation
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
 
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...
 

Similar to 8051 addressing modes

Microcontroller 8051 soft
Microcontroller 8051  softMicrocontroller 8051  soft
Microcontroller 8051 softbaluusa8
 
MICROCONTROLLERS-module2 (7).pptx
MICROCONTROLLERS-module2 (7).pptxMICROCONTROLLERS-module2 (7).pptx
MICROCONTROLLERS-module2 (7).pptxAmoghR3
 
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 Technogroovy India
 
Microcontroller 8051- soft.ppt
Microcontroller 8051- soft.pptMicrocontroller 8051- soft.ppt
Microcontroller 8051- soft.pptsteffydean
 
8051 addressing modes
8051 addressing modes8051 addressing modes
8051 addressing modesVima Mali
 
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.pdfShreeKrishnaTarai
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontrollerjokersclown57
 
Addressing Modes of 8051.pptx
Addressing Modes of 8051.pptxAddressing Modes of 8051.pptx
Addressing Modes of 8051.pptxTumkurInfomedia
 
New text document
New text documentNew text document
New text documentzocaniveb
 
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 TrainingTechnogroovy
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051Dr. AISHWARYA N
 
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-phpapp01bvenkanna
 

Similar to 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
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
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
 

Recently uploaded

Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptxNikhil Raut
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 

Recently uploaded (20)

Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 

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