SlideShare ist ein Scribd-Unternehmen logo
1 von 21
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!!

Weitere ähnliche Inhalte

Was ist angesagt?

8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller Notes
Dr.YNM
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
Prof. Swapnil V. Kaware
 
T-states in microprocessor 8085
T-states in microprocessor 8085T-states in microprocessor 8085
T-states in microprocessor 8085
yedles
 

Was ist angesagt? (20)

DAC Interfacing with 8051.pdf
DAC Interfacing with 8051.pdfDAC Interfacing with 8051.pdf
DAC Interfacing with 8051.pdf
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
 
Branch instructions in 8051 micrcocontroller
Branch instructions in 8051 micrcocontrollerBranch instructions in 8051 micrcocontroller
Branch instructions in 8051 micrcocontroller
 
Counters & time delay
Counters & time delayCounters & time delay
Counters & time delay
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
 
8085 interfacing with memory chips
8085 interfacing with memory chips8085 interfacing with memory chips
8085 interfacing with memory chips
 
8086 microprocessor
8086 microprocessor8086 microprocessor
8086 microprocessor
 
LCD Interacing with 8051
LCD Interacing with 8051LCD Interacing with 8051
LCD Interacing with 8051
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing Modes
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller Notes
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller ppt
 
Hardware View of Intel 8051
Hardware View of Intel 8051Hardware View of Intel 8051
Hardware View of Intel 8051
 
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
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
 
T-states in microprocessor 8085
T-states in microprocessor 8085T-states in microprocessor 8085
T-states in microprocessor 8085
 
Digital electronics logic families
Digital electronics logic familiesDigital electronics logic families
Digital electronics logic families
 
8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directives
 
Logic families
Logic  familiesLogic  families
Logic families
 

Andere mochten auch

Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
Ashim Saha
 
16 subroutine
16 subroutine16 subroutine
16 subroutine
fyjordan9
 
Heba Qotb Portfolio
Heba Qotb PortfolioHeba Qotb Portfolio
Heba Qotb Portfolio
Heba Qotb
 
Хоменко О.Н.
Хоменко О.Н.Хоменко О.Н.
Хоменко О.Н.
sashatasha98
 
Oliver Gooden Resume 1
Oliver Gooden Resume 1Oliver Gooden Resume 1
Oliver Gooden Resume 1
Oliver Gooden
 
Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)
Safin Biswas
 

Andere mochten auch (20)

Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 
16 subroutine
16 subroutine16 subroutine
16 subroutine
 
Stacks & subroutines 1
Stacks & subroutines 1Stacks & subroutines 1
Stacks & subroutines 1
 
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)
 

Ähnlich wie Subroutine in 8051 microcontroller

NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docxNIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
curwenmichaela
 
Plc example presentation
Plc example presentationPlc example presentation
Plc example presentation
Roshit 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Kürzlich hochgeladen (20)

Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
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
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
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
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
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
 

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