SlideShare a Scribd company logo
Subroutine in 8051
Microcontroller
By, Bhadresh Savani (140110120046)
Ronak Sejani (140110120047)
Aashiv Shah (140110120048)
Guided by, B. R. Hindocha
What is Subroutine?
Subroutine is a group of instructions Written separately from the main program to
perform a function that occurs repeatedly in the main program.
When you call a subroutine implementation of the current program is stopped, the
program counter PC is loaded with the memory location of the subroutine, running
up to the RET instruction (end of subroutine), where produce a return to the main
program resumes running.
Subroutines...
• Perform specific functions and are not operating on their own.
• Are always linked to a major program or other subroutines.
• Can be called many times as necessary as it reduces the code the program
to have the effect of code reuse.
• Allow the division of program blocks as perform the function of structure.
Providing greater visibility and understanding of it.
INSTRUCTIONS of Subroutine in
8051 Microcontroller
ACALL
LCALL
RET
RETI
ACALL INSTUCTION
Function: Absolute Call Within 2K Block
Syntax: ACALL code address
Description: ACALL unconditionally calls a subroutine at the indicated code
address. ACALL pushes the address of the instruction that follows ACALL onto
the stack, least-significant-byte first, most-significant-byte second. The Program
Counter is then updated so that program execution continues at the indicated
address.
The new value for the Program Counter is calculated by replacing the least-
significant-byte of the Program Counter with the second byte of the ACALL
instruction, and replacing bits 0-2 of the most-significant-byte of the Program
Counter with 3 bits that indicate the page. Bits 3-7 of the most-significant-byte of
the Program Counter remain unchanged.
Since only 11 bits of the Program Counter are affected by ACALL, calls may only
be made to routines located within the same 2k block as the first byte that follows
ACALL.
Instructions OpCode Bytes Cycles Flags
ACALL page0 0x11 2 2 None
ACALL page1 0x31 2 2 None
ACALL page2 0x51 2 2 None
ACALL page3 0x71 2 2 None
ACALL page4 0x91 2 2 None
ACALL page5 0xB1 2 2 None
ACALL page6 0xD1 2 2 None
ACALL page7 0xF1 2 2 None
LCALL INSTRUCTION
Function: Long Call
Syntax: LCALL code addr
Description: LCALL calls a program subroutine. LCALL increments the program
counter by 3 (to point to the instruction following LCALL) and pushes that value
onto the stack (low byte first, high byte second). The Program Counter is then set
to the 16-bit value which follows the LCALL opcode, causing program execution to
continue at that address.
Instructions OpCode Bytes Cycles Flags
LCALL 0x12 3 2 None
Difference B/W ACALL and LCALL
ACALL stands for absolute call while LCALL stands for long call.
ACALL allows you to jump to a subroutine within the same 2K page while
LCALL allows you to jump to a subroutine anywhere in the 64K code space.
The Advantage of ACALL over LCALL is that it is a 2-byte instruction while
LCALL is a 3-byte instruction.
RET INSTRUCTION
Function: Return From Subroutine
Syntax: RET
Description: RET is used to return from a subroutine previously called by LCALL
or ACALL. Program execution continues at the address that is calculated by
popping the topmost 2 bytes off the stack. The most-significant-byte is popped
off the stack first, followed by the least-significant-byte.
Instructions OpCode Bytes Cycles Flags
RET 0x22 1 2 None
RETI instruction
Function: Return from Interrupt
Syntax: RETI
Description:The RETI instruction is used to end an interrupt service routine. This
instruction pops the high-order and low-order bytes of the PC (and decrements
the stack pointer by 2) and restores the interrupt logic to accept additional
interrupts. No other registers are affected by this instruction.
The RETI instruction does not restore the PSW to its value before the interrupt.
The interrupt service routine must save and restore the PSW.
Execution returns to the instruction immediately after the point at which the
interrupt was detected. If another interrupt was pending when the RETI
instruction is executed, one instruction at the return address is executed before
the pending interrupt is processed.
Instructions OpCode Bytes Cycles Flags
RETI 0x32 1 2 None
Difference B/W RET and RETI
RETI releases the interrupts of the same level of priority than the interrupt that has
caused the branch, and RET doesn't.
RET stands for Return from Stack.
RETI stands for Return from Stack of Interrupt.
ADVANTAGE OF SUBROUTINE
Minimize the content of the sentences in the main program.
Dividing a large programming task among various programmers, or various
stages of a project.
Improving Traceability.
Make the program easier and it takes up less space in the ROM.
Disadvantages of SUBROUTINE
Invoking a subroutine (versus using inline code) imposes some computational
overhead in the call mechanism.
The subroutine typically requires standard housekeeping code – both at entry
to, and exit from, the function.
Resources
1. http://www.alciro.org/alciro/microcontroladores-8051_24/subrutina-subprograma_357_en.htm
2. https://en.wikipedia.org/wiki/Subroutine
3. http://www.edsim51.com/8051Notes/8051/subroutines.html
4. http://www.hobbyprojects.com/8051_tutorial/acall_absolute_call.html
Thank you!!

More Related Content

What's hot

8085 instruction set
8085 instruction set8085 instruction set
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacing
Ankur Mahajan
 
Presentation on 8086 Microprocessor
Presentation  on   8086 MicroprocessorPresentation  on   8086 Microprocessor
Presentation on 8086 Microprocessor
Nahian Ahmed
 
Sensor interfacing in 8051
Sensor interfacing in 8051Sensor interfacing in 8051
Sensor interfacing in 8051
Irfan Ahmad
 
Timing diagram 8085 microprocessor
Timing diagram 8085 microprocessorTiming diagram 8085 microprocessor
Timing diagram 8085 microprocessor
Velalar College of Engineering and Technology
 
Interfacing external memory in 8051
Interfacing external memory in 8051Interfacing external memory in 8051
Interfacing external memory in 8051
ssuser3a47cb
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller NotesDr.YNM
 
8051 interfacing
8051 interfacing8051 interfacing
8051 interfacing
KanchanPatil34
 
Interfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 MicrocontrollerInterfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 Microcontroller
Pantech ProLabs India Pvt Ltd
 
Digital electronics logic families
Digital electronics logic familiesDigital electronics logic families
Digital electronics logic families
BLESSINAR0
 
8051 ch9-950217
8051 ch9-9502178051 ch9-950217
8051 ch9-950217
Gopal Krishna Murthy C R
 
Stacks & subroutines 1
Stacks & subroutines 1Stacks & subroutines 1
Stacks & subroutines 1
deval patel
 
Serial Communication in 8051
Serial Communication in 8051Serial Communication in 8051
Serial Communication in 8051
Sudhanshu Janwadkar
 
I o ports.ppt
I o ports.pptI o ports.ppt
I o ports.ppt
Pradeep V Dev
 
Relay interfacing with 8051
Relay interfacing with 8051Relay interfacing with 8051
Relay interfacing with 8051
Pratik Phadte
 
Project report on the Digital clock using RTC and microcontroller 8051
Project report on the Digital clock using RTC and microcontroller 8051Project report on the Digital clock using RTC and microcontroller 8051
Project report on the Digital clock using RTC and microcontroller 8051
Maulik Sanchela
 
Memory organization of 8051
Memory organization of 8051Memory organization of 8051
Memory organization of 8051Muthu Manickam
 
Interfacing rs232
Interfacing rs232Interfacing rs232
Interfacing rs232PRADEEP
 
8051 block diagram
8051 block diagram8051 block diagram
8051 block diagram
DominicHendry
 

What's hot (20)

8085 instruction set
8085 instruction set8085 instruction set
8085 instruction set
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacing
 
Presentation on 8086 Microprocessor
Presentation  on   8086 MicroprocessorPresentation  on   8086 Microprocessor
Presentation on 8086 Microprocessor
 
Sensor interfacing in 8051
Sensor interfacing in 8051Sensor interfacing in 8051
Sensor interfacing in 8051
 
Timing diagram 8085 microprocessor
Timing diagram 8085 microprocessorTiming diagram 8085 microprocessor
Timing diagram 8085 microprocessor
 
Interfacing external memory in 8051
Interfacing external memory in 8051Interfacing external memory in 8051
Interfacing external memory in 8051
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller Notes
 
RS 232
RS 232RS 232
RS 232
 
8051 interfacing
8051 interfacing8051 interfacing
8051 interfacing
 
Interfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 MicrocontrollerInterfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 Microcontroller
 
Digital electronics logic families
Digital electronics logic familiesDigital electronics logic families
Digital electronics logic families
 
8051 ch9-950217
8051 ch9-9502178051 ch9-950217
8051 ch9-950217
 
Stacks & subroutines 1
Stacks & subroutines 1Stacks & subroutines 1
Stacks & subroutines 1
 
Serial Communication in 8051
Serial Communication in 8051Serial Communication in 8051
Serial Communication in 8051
 
I o ports.ppt
I o ports.pptI o ports.ppt
I o ports.ppt
 
Relay interfacing with 8051
Relay interfacing with 8051Relay interfacing with 8051
Relay interfacing with 8051
 
Project report on the Digital clock using RTC and microcontroller 8051
Project report on the Digital clock using RTC and microcontroller 8051Project report on the Digital clock using RTC and microcontroller 8051
Project report on the Digital clock using RTC and microcontroller 8051
 
Memory organization of 8051
Memory organization of 8051Memory organization of 8051
Memory organization of 8051
 
Interfacing rs232
Interfacing rs232Interfacing rs232
Interfacing rs232
 
8051 block diagram
8051 block diagram8051 block diagram
8051 block diagram
 

Viewers also liked

Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutineAshim Saha
 
16 subroutine
16 subroutine16 subroutine
16 subroutinefyjordan9
 
8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directives
SARITHA REDDY
 
Unit 1-subroutines in perl
Unit 1-subroutines in perlUnit 1-subroutines in perl
Unit 1-subroutines in perl
sana mateen
 
Subroutine & string in 8086 Microprocessor
Subroutine & string in 8086 MicroprocessorSubroutine & string in 8086 Microprocessor
Subroutine & string in 8086 Microprocessor
Mustafa AL-Timemmie
 
SUNITHA RAJENDRAN
SUNITHA RAJENDRANSUNITHA RAJENDRAN
SUNITHA RAJENDRAN
SUNITHARAJENDRAN
 
Strategic Marketing and Sales for SparXX
Strategic Marketing and Sales for SparXXStrategic Marketing and Sales for SparXX
Strategic Marketing and Sales for SparXX
Kristin Slice
 
GoGrid CDN - Webinar about GoGrid's Content Delivery Network
GoGrid CDN - Webinar about GoGrid's Content Delivery NetworkGoGrid CDN - Webinar about GoGrid's Content Delivery Network
GoGrid CDN - Webinar about GoGrid's Content Delivery Network
GoGrid Cloud Hosting
 
Heba Qotb Portfolio
Heba Qotb PortfolioHeba Qotb Portfolio
Heba Qotb PortfolioHeba Qotb
 
Хоменко О.Н.
Хоменко О.Н.Хоменко О.Н.
Хоменко О.Н.
sashatasha98
 
Turmeric soa symposium_v1.0
Turmeric soa symposium_v1.0Turmeric soa symposium_v1.0
Turmeric soa symposium_v1.0
Jose Alvarez Muguerza
 
Comprehensive overview of melasma
Comprehensive overview of melasmaComprehensive overview of melasma
Comprehensive overview of melasma
Daifallah Almansouri
 
ENCIMERA FRANKE 4 PIN 630
ENCIMERA  FRANKE 4 PIN 630ENCIMERA  FRANKE 4 PIN 630
ENCIMERA FRANKE 4 PIN 630
Alsako Electrodomésticos
 
Melasma
MelasmaMelasma
Melasma
Medicine
 
8 interrupt 8051
8 interrupt 80518 interrupt 8051
8 interrupt 8051
daniemol
 
Applications of microprocessor
Applications of microprocessorApplications of microprocessor
Applications of microprocessor
Anjali Agrawal
 
Oliver Gooden Resume 1
Oliver Gooden Resume 1Oliver Gooden Resume 1
Oliver Gooden Resume 1Oliver Gooden
 
Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)Safin Biswas
 

Viewers also liked (20)

Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 
16 subroutine
16 subroutine16 subroutine
16 subroutine
 
8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directives
 
Unit 1-subroutines in perl
Unit 1-subroutines in perlUnit 1-subroutines in perl
Unit 1-subroutines in perl
 
Subroutine & string in 8086 Microprocessor
Subroutine & string in 8086 MicroprocessorSubroutine & string in 8086 Microprocessor
Subroutine & string in 8086 Microprocessor
 
SUNITHA RAJENDRAN
SUNITHA RAJENDRANSUNITHA RAJENDRAN
SUNITHA RAJENDRAN
 
红枣粉
红枣粉红枣粉
红枣粉
 
山茱萸
山茱萸山茱萸
山茱萸
 
Strategic Marketing and Sales for SparXX
Strategic Marketing and Sales for SparXXStrategic Marketing and Sales for SparXX
Strategic Marketing and Sales for SparXX
 
GoGrid CDN - Webinar about GoGrid's Content Delivery Network
GoGrid CDN - Webinar about GoGrid's Content Delivery NetworkGoGrid CDN - Webinar about GoGrid's Content Delivery Network
GoGrid CDN - Webinar about GoGrid's Content Delivery Network
 
Heba Qotb Portfolio
Heba Qotb PortfolioHeba Qotb Portfolio
Heba Qotb Portfolio
 
Хоменко О.Н.
Хоменко О.Н.Хоменко О.Н.
Хоменко О.Н.
 
Turmeric soa symposium_v1.0
Turmeric soa symposium_v1.0Turmeric soa symposium_v1.0
Turmeric soa symposium_v1.0
 
Comprehensive overview of melasma
Comprehensive overview of melasmaComprehensive overview of melasma
Comprehensive overview of melasma
 
ENCIMERA FRANKE 4 PIN 630
ENCIMERA  FRANKE 4 PIN 630ENCIMERA  FRANKE 4 PIN 630
ENCIMERA FRANKE 4 PIN 630
 
Melasma
MelasmaMelasma
Melasma
 
8 interrupt 8051
8 interrupt 80518 interrupt 8051
8 interrupt 8051
 
Applications of microprocessor
Applications of microprocessorApplications of microprocessor
Applications of microprocessor
 
Oliver Gooden Resume 1
Oliver Gooden Resume 1Oliver Gooden Resume 1
Oliver Gooden Resume 1
 
Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)
 

Similar to Subroutine in 8051 microcontroller

assembler_full_slides.ppt
assembler_full_slides.pptassembler_full_slides.ppt
assembler_full_slides.ppt
Ashwini864432
 
Advanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILPAdvanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILP
A B Shinde
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
Omar Sanchez
 
Micro PLC_Manal for new comer plc learner
Micro PLC_Manal for new comer plc learnerMicro PLC_Manal for new comer plc learner
Micro PLC_Manal for new comer plc learner
ssuser6cedd3
 
Subroutine
SubroutineSubroutine
viva q&a for mp lab
viva q&a for mp labviva q&a for mp lab
viva q&a for mp lab
g yugandhar srinivas
 
Advanced Microprocessors
Advanced MicroprocessorsAdvanced Microprocessors
Advanced Microprocessors
BuddiesSairamit
 
Ecet 340 Teaching Effectively--tutorialrank.com
Ecet 340 Teaching Effectively--tutorialrank.comEcet 340 Teaching Effectively--tutorialrank.com
Ecet 340 Teaching Effectively--tutorialrank.com
Soaps97
 
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docxNIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
curwenmichaela
 
ECET 340 Effective Communication/tutorialrank.com
 ECET 340 Effective Communication/tutorialrank.com ECET 340 Effective Communication/tutorialrank.com
ECET 340 Effective Communication/tutorialrank.com
jonhson203
 
Embedded systems ppt ii
Embedded systems ppt iiEmbedded systems ppt ii
Embedded systems ppt ii
anishgoel
 
Modul PLC Programming.pdf
Modul PLC Programming.pdfModul PLC Programming.pdf
Modul PLC Programming.pdf
MOCHAMAD RIZKY BINTANG ARDYANSYAH
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mapping
OsaMa Hasan
 
Introduction to Microcontrollers
Introduction to MicrocontrollersIntroduction to Microcontrollers
Introduction to Microcontrollers
SaravananVijayakumar4
 
Customizable Microprocessor design on Nexys 3 Spartan FPGA Board
Customizable Microprocessor design on Nexys 3 Spartan FPGA BoardCustomizable Microprocessor design on Nexys 3 Spartan FPGA Board
Customizable Microprocessor design on Nexys 3 Spartan FPGA Board
Bharat Biyani
 
Floating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGAFloating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGA
Azhar Syed
 
Plc example presentation
Plc example presentationPlc example presentation
Plc example presentationRoshit Kadiru
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
vipinkmenon1
 

Similar to Subroutine in 8051 microcontroller (20)

assembler_full_slides.ppt
assembler_full_slides.pptassembler_full_slides.ppt
assembler_full_slides.ppt
 
Advanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILPAdvanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILP
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
 
Micro PLC_Manal for new comer plc learner
Micro PLC_Manal for new comer plc learnerMicro PLC_Manal for new comer plc learner
Micro PLC_Manal for new comer plc learner
 
Subroutine
SubroutineSubroutine
Subroutine
 
viva q&a for mp lab
viva q&a for mp labviva q&a for mp lab
viva q&a for mp lab
 
Advanced Microprocessors
Advanced MicroprocessorsAdvanced Microprocessors
Advanced Microprocessors
 
Ecet 340 Teaching Effectively--tutorialrank.com
Ecet 340 Teaching Effectively--tutorialrank.comEcet 340 Teaching Effectively--tutorialrank.com
Ecet 340 Teaching Effectively--tutorialrank.com
 
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docxNIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
 
ECET 340 Effective Communication/tutorialrank.com
 ECET 340 Effective Communication/tutorialrank.com ECET 340 Effective Communication/tutorialrank.com
ECET 340 Effective Communication/tutorialrank.com
 
Embedded systems ppt ii
Embedded systems ppt iiEmbedded systems ppt ii
Embedded systems ppt ii
 
Modul PLC Programming.pdf
Modul PLC Programming.pdfModul PLC Programming.pdf
Modul PLC Programming.pdf
 
Assembler
AssemblerAssembler
Assembler
 
Assembler
AssemblerAssembler
Assembler
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mapping
 
Introduction to Microcontrollers
Introduction to MicrocontrollersIntroduction to Microcontrollers
Introduction to Microcontrollers
 
Customizable Microprocessor design on Nexys 3 Spartan FPGA Board
Customizable Microprocessor design on Nexys 3 Spartan FPGA BoardCustomizable Microprocessor design on Nexys 3 Spartan FPGA Board
Customizable Microprocessor design on Nexys 3 Spartan FPGA Board
 
Floating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGAFloating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGA
 
Plc example presentation
Plc example presentationPlc example presentation
Plc example presentation
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 

Recently uploaded

LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 

Recently uploaded (20)

LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 

Subroutine in 8051 microcontroller

  • 1. Subroutine in 8051 Microcontroller By, Bhadresh Savani (140110120046) Ronak Sejani (140110120047) Aashiv Shah (140110120048) Guided by, B. R. Hindocha
  • 2. What is Subroutine? Subroutine is a group of instructions Written separately from the main program to perform a function that occurs repeatedly in the main program. When you call a subroutine implementation of the current program is stopped, the program counter PC is loaded with the memory location of the subroutine, running up to the RET instruction (end of subroutine), where produce a return to the main program resumes running.
  • 3. Subroutines... • Perform specific functions and are not operating on their own. • Are always linked to a major program or other subroutines. • Can be called many times as necessary as it reduces the code the program to have the effect of code reuse. • Allow the division of program blocks as perform the function of structure. Providing greater visibility and understanding of it.
  • 4. INSTRUCTIONS of Subroutine in 8051 Microcontroller ACALL LCALL RET RETI
  • 5. ACALL INSTUCTION Function: Absolute Call Within 2K Block Syntax: ACALL code address Description: ACALL unconditionally calls a subroutine at the indicated code address. ACALL pushes the address of the instruction that follows ACALL onto the stack, least-significant-byte first, most-significant-byte second. The Program Counter is then updated so that program execution continues at the indicated address.
  • 6. The new value for the Program Counter is calculated by replacing the least- significant-byte of the Program Counter with the second byte of the ACALL instruction, and replacing bits 0-2 of the most-significant-byte of the Program Counter with 3 bits that indicate the page. Bits 3-7 of the most-significant-byte of the Program Counter remain unchanged. Since only 11 bits of the Program Counter are affected by ACALL, calls may only be made to routines located within the same 2k block as the first byte that follows ACALL.
  • 7. Instructions OpCode Bytes Cycles Flags ACALL page0 0x11 2 2 None ACALL page1 0x31 2 2 None ACALL page2 0x51 2 2 None ACALL page3 0x71 2 2 None ACALL page4 0x91 2 2 None ACALL page5 0xB1 2 2 None ACALL page6 0xD1 2 2 None ACALL page7 0xF1 2 2 None
  • 8. LCALL INSTRUCTION Function: Long Call Syntax: LCALL code addr Description: LCALL calls a program subroutine. LCALL increments the program counter by 3 (to point to the instruction following LCALL) and pushes that value onto the stack (low byte first, high byte second). The Program Counter is then set to the 16-bit value which follows the LCALL opcode, causing program execution to continue at that address.
  • 9. Instructions OpCode Bytes Cycles Flags LCALL 0x12 3 2 None
  • 10. Difference B/W ACALL and LCALL ACALL stands for absolute call while LCALL stands for long call. ACALL allows you to jump to a subroutine within the same 2K page while LCALL allows you to jump to a subroutine anywhere in the 64K code space. The Advantage of ACALL over LCALL is that it is a 2-byte instruction while LCALL is a 3-byte instruction.
  • 11. RET INSTRUCTION Function: Return From Subroutine Syntax: RET Description: RET is used to return from a subroutine previously called by LCALL or ACALL. Program execution continues at the address that is calculated by popping the topmost 2 bytes off the stack. The most-significant-byte is popped off the stack first, followed by the least-significant-byte.
  • 12. Instructions OpCode Bytes Cycles Flags RET 0x22 1 2 None
  • 13. RETI instruction Function: Return from Interrupt Syntax: RETI Description:The RETI instruction is used to end an interrupt service routine. This instruction pops the high-order and low-order bytes of the PC (and decrements the stack pointer by 2) and restores the interrupt logic to accept additional interrupts. No other registers are affected by this instruction.
  • 14. The RETI instruction does not restore the PSW to its value before the interrupt. The interrupt service routine must save and restore the PSW. Execution returns to the instruction immediately after the point at which the interrupt was detected. If another interrupt was pending when the RETI instruction is executed, one instruction at the return address is executed before the pending interrupt is processed.
  • 15. Instructions OpCode Bytes Cycles Flags RETI 0x32 1 2 None
  • 16. Difference B/W RET and RETI RETI releases the interrupts of the same level of priority than the interrupt that has caused the branch, and RET doesn't. RET stands for Return from Stack. RETI stands for Return from Stack of Interrupt.
  • 17. ADVANTAGE OF SUBROUTINE Minimize the content of the sentences in the main program. Dividing a large programming task among various programmers, or various stages of a project. Improving Traceability. Make the program easier and it takes up less space in the ROM.
  • 18. Disadvantages of SUBROUTINE Invoking a subroutine (versus using inline code) imposes some computational overhead in the call mechanism. The subroutine typically requires standard housekeeping code – both at entry to, and exit from, the function.
  • 19.
  • 20. Resources 1. http://www.alciro.org/alciro/microcontroladores-8051_24/subrutina-subprograma_357_en.htm 2. https://en.wikipedia.org/wiki/Subroutine 3. http://www.edsim51.com/8051Notes/8051/subroutines.html 4. http://www.hobbyprojects.com/8051_tutorial/acall_absolute_call.html