SlideShare a Scribd company logo
BRANCH INSTRUCTIONS CALL, JMP, RET
Branching instructions Program branching instructions are used to control the flow of actions  in a program Some instructions provide  decision making  capabilities and transfer control to other parts of the program. e.g.  conditional and unconditional branches
CALL    ACALL & LCALL The 8051 provides 2 forms for the CALL instruction: Absolute Call – ACALL Uses  an 11-bit address The subroutine must be within the  same 2K page . Long Call – LCALL Uses a  16-bit address The subroutine can be  anywhere. Both forms push the 16-bit address of PC on the stack and update the stack pointer.
Absolute Call – ACALL addr11 This instruction unconditionally calls a subroutine indicated by the address 2 byte instruction : The upper 3-bits of the address combine with the 5-bit opcode to form the  1 st  byte  and the lower 8-bits of the address form the  2 nd  byte Eg.  ACALL  LOC_SUB If  SP=07H  initially  label  “LOC_SUB”  is at memory  0567H, then executing instruction at  0230H (PC), SP=09H,  internal RAM locations  08H  and  09H  will  contain  32H and  02H  respectively and  PC=0567H
LONG CALL - LCALL addr16 It is a Long call, the subroutine may therefore begin anywhere in the full  64 kB program  memory address space 3 byte instruction LCALL  LOC_SUB Initially,  SP=07H   label  “LOC_SUB”  is at memory  4100H Executing the  instruction at 0230H ( PC), SP=09H , internal RAM locations  08H  and 09H  contain  33H  and 02H  respectively and  PC=4100H
RETURN    RET & RETI The 8051 provides  2 forms  for the return instruction: Return from subroutine – RET Pop the return address  from the stack and continue execution there. Return from ISR – RETI Pop the return address  from the stack. Restore the  interrupt logic  to accept additional interrupts at the  same priority level as the one just processed . Continue execution at the address retrieved from the stack. The  PSW  is  not  automatically restored.
JUMP   SJMP  The 8051 provides  four different types  of unconditional jump instructions: Short Jump – SJMP addr  Uses an  8-bit signed offset relative to the 1 st  byte of the next instruction . the range of destination allowed is from  -128 to+127 bytes  from the instruction SJMP RELSRT If the label  RELSRT is at program memory location 0120H  and the  SJMP  instruction is located at address  0100H ( PC)  ,after executing the instruction,  PC=0120H
JUMP    LJMP Long Jump – LJMP Uses a  16-bit address . 3 byte instruction  capable of referencing any location in the entire 64K of program memory. LJMP  FAR_ADR If the label  FAR_ADR  is at program memory location  3456H the  LJMP instruction at location 0120H (PC) After instruction, it loads the  PC with 3456H
JUMP    AJMP Absolute Jump – AJMP Uses an  11-bit address . 2 byte instruction The 11-bit address is substituted for the lower 11-bits of the PC to calculate the 16-bit address of the target. The location referenced must be within the 2K Byte AJMP NEAR If the  label NEAR  is at program memory location  0120H , the  AJMP  instruction at location  0234H (PC)  loads the  PC with 0120H
Indirect Jump This instruction  adds  the 8-bit unsigned value of the  ACC to the 16-bit data pointer  and the resulting sum is returned to the PC Neither ACC nor DPTR is altered No flags are affected MOV DPTR, #LOOK_TBL JMP @A + DPTR LOOK_TBL: AJMP LOC0 AJMP LOC1 AJMP LOC2 If the  ACC=02H , execution jumps to  LOC2 AJMP is a  two byte instruction
CONDITIONAL JUMP The 8051 supports  different conditional jump  instructions. ALL conditional jump instructions use an 8-bit address. Jump on Zero – JZ / JNZ Jump if the A == 0 / A != 0 The check is done at the time of the instruction execution. Jump on Carry – JC / JNC Jump if the C flag is set / cleared.
CONDITIONAL JUMP Jump on Bit – JB / JNB Jump if the specified bit is set / cleared. Any addressable bit can be specified. Jump if the Bit is set then Clear the bit – JBC Jump if the specified bit is set. Then clear the bit.
Compare and Jump if Not Equal – CJNE Compare the magnitude of the two operands and jump if they are not equal. The values are considered to be unsigned. The Carry flag is set / cleared appropriately. CJNE A, direct, rel CJNE A, #data, rel CJNE Rn, #data, rel CJNE @Ri, #data, rel
Decrement and Jump if Not Zero – DJNZ Decrement the first operand by 1  and  jump  to the location identified by the  second operand  if the  resulting value is not zero. DJNZ 20H,LOC1 DJNZ 30H,LOC2 DJNZ 40H,LOC3 If internal RAM locations  20H, 30H and 40H  contain the values  01H, 5FH and 16H  respectively,  the above instruction sequence will cause a  jump to the instruction at LOC2 , with the  values 00H, 5EH, and 15H  in the 3 RAM locations
NOP This is the  no operation  instruction The instruction takes one machine cycle operation time Hence it is useful to time the  ON/OFF bit  of an output port CLR P1.2 NOP NOP NOP NOP SETB P1.2

More Related Content

PPTX
Differential amplifier
PDF
VLSI Fresher Resume
PDF
PPTX
Generation and detection of psk and fsk
PPTX
3673 mosfet
PDF
Verilog full adder in dataflow & gate level modelling style.
PPT
Arithmetic & logical operations in 8051
PPT
Programmable array logic
Differential amplifier
VLSI Fresher Resume
Generation and detection of psk and fsk
3673 mosfet
Verilog full adder in dataflow & gate level modelling style.
Arithmetic & logical operations in 8051
Programmable array logic

What's hot (20)

PDF
5. differential amplifier
PPT
DAC-digital to analog converter
PPTX
Radar Systems- Unit-II : CW and Frequency Modulated Radar
PPTX
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I Core of Embedded Systems
PDF
Digital base band modulation
PPTX
Optical Fiber Communication System
PDF
Seven segment interfacing with 8051.pdf
PPTX
integrator and differentiator op-amp
PPTX
Chebyshev filter
DOCX
UNIT I- CPLD & FPGA ARCHITECTURE & APPLICATIONS
DOCX
A Computers Architecture project on Barrel shifters
PPTX
Digital modulation techniques...
PPTX
Fault detection and test minimization methods
PDF
DAC Interfacing with 8051.pdf
PDF
Thyristor
PDF
Design of IIR filters
PPTX
Proteus Circuit Simulation
PPTX
Line coding
PPTX
Stick Diagram
5. differential amplifier
DAC-digital to analog converter
Radar Systems- Unit-II : CW and Frequency Modulated Radar
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I Core of Embedded Systems
Digital base band modulation
Optical Fiber Communication System
Seven segment interfacing with 8051.pdf
integrator and differentiator op-amp
Chebyshev filter
UNIT I- CPLD & FPGA ARCHITECTURE & APPLICATIONS
A Computers Architecture project on Barrel shifters
Digital modulation techniques...
Fault detection and test minimization methods
DAC Interfacing with 8051.pdf
Thyristor
Design of IIR filters
Proteus Circuit Simulation
Line coding
Stick Diagram
Ad

Viewers also liked (14)

PPT
Instruction set of 8085
PPT
8051 instruction set
PPTX
boolean 8051
PPT
Instruction set-of-8085
PDF
Embedded systems ppt ii
PDF
8051 micro controllers Instruction set
DOCX
8051 data types and directives
PPTX
Uc 2(vii)
PPTX
Instruction set of 8085 Microprocessor By Er. Swapnil Kaware
PDF
8051 assembly programming
PDF
Interrupt
PPT
Addressing mode of 8051
PPT
Addressing modes of 8051
PPTX
8086 microprocessor-architecture
Instruction set of 8085
8051 instruction set
boolean 8051
Instruction set-of-8085
Embedded systems ppt ii
8051 micro controllers Instruction set
8051 data types and directives
Uc 2(vii)
Instruction set of 8085 Microprocessor By Er. Swapnil Kaware
8051 assembly programming
Interrupt
Addressing mode of 8051
Addressing modes of 8051
8086 microprocessor-architecture
Ad

Similar to branch ins 8051 (20)

PPTX
Addressing Modes
PDF
Microcontroladores: introducción a la programación en lenguaje ensamblador AVR
PPTX
Microprocessor Systems - MCU Applications with 8051 MCU and Assembly Language...
PPTX
2. Instruction Set.pptx huishiuhfuidhiuhdfuhdu
PPT
1344 Alp Of 8086
PDF
Https _doc-0o-c4-apps-viewer.googleusercontent
PDF
Stack and subroutine
PPTX
B sc e 5.2 mp unit 2 soft ware(alp)
PDF
8085 branching instruction
PDF
mca is a microcontroller and accmulator is a third year couse
PPT
Chap 3_2.ppt
PPT
Instruction set Madha Insstitute of Engineering
PPT
INTRUCTION SET OF 8086 FOR MICROPROCESSOR
PPTX
EPC Module-5 ES.pptxModule-5 ES.pptxModule-5 ES.pptx
PPTX
Programming basic computer
PPT
Lecture_4__8051_Instruction_Set__Rv01.ppt
PPTX
Embedded system and Internet of things-1.pptx
PDF
3 jump, loop and call instructions
PPT
Micro controller(pratheesh)
PPT
instruction_set_8051_microcontroller.ppt
Addressing Modes
Microcontroladores: introducción a la programación en lenguaje ensamblador AVR
Microprocessor Systems - MCU Applications with 8051 MCU and Assembly Language...
2. Instruction Set.pptx huishiuhfuidhiuhdfuhdu
1344 Alp Of 8086
Https _doc-0o-c4-apps-viewer.googleusercontent
Stack and subroutine
B sc e 5.2 mp unit 2 soft ware(alp)
8085 branching instruction
mca is a microcontroller and accmulator is a third year couse
Chap 3_2.ppt
Instruction set Madha Insstitute of Engineering
INTRUCTION SET OF 8086 FOR MICROPROCESSOR
EPC Module-5 ES.pptxModule-5 ES.pptxModule-5 ES.pptx
Programming basic computer
Lecture_4__8051_Instruction_Set__Rv01.ppt
Embedded system and Internet of things-1.pptx
3 jump, loop and call instructions
Micro controller(pratheesh)
instruction_set_8051_microcontroller.ppt

More from VJ Aiswaryadevi (14)

PPTX
memory 8051
PPT
logical 8051
PPT
interrupts
PPT
arithmetic ins in 8051
PPT
8051 archi
PPT
8051 microprocessor
PPTX
8051 microprocessor
PPT
Groupware
PDF
302 B+Tree Ind Hash
PPT
storage media
PPT
memory 8051
logical 8051
interrupts
arithmetic ins in 8051
8051 archi
8051 microprocessor
8051 microprocessor
Groupware
302 B+Tree Ind Hash
storage media

Recently uploaded (20)

PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
STKI Israel Market Study 2025 version august
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
project resource management chapter-09.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
Tartificialntelligence_presentation.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Hybrid model detection and classification of lung cancer
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Getting started with AI Agents and Multi-Agent Systems
Enhancing emotion recognition model for a student engagement use case through...
STKI Israel Market Study 2025 version august
A comparative study of natural language inference in Swahili using monolingua...
Module 1.ppt Iot fundamentals and Architecture
O2C Customer Invoices to Receipt V15A.pptx
project resource management chapter-09.pdf
Chapter 5: Probability Theory and Statistics
Tartificialntelligence_presentation.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
1. Introduction to Computer Programming.pptx
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Web App vs Mobile App What Should You Build First.pdf
WOOl fibre morphology and structure.pdf for textiles
Final SEM Unit 1 for mit wpu at pune .pptx
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Hybrid model detection and classification of lung cancer
NewMind AI Weekly Chronicles – August ’25 Week III
cloud_computing_Infrastucture_as_cloud_p
Getting started with AI Agents and Multi-Agent Systems

branch ins 8051

  • 2. Branching instructions Program branching instructions are used to control the flow of actions in a program Some instructions provide decision making capabilities and transfer control to other parts of the program. e.g. conditional and unconditional branches
  • 3. CALL  ACALL & LCALL The 8051 provides 2 forms for the CALL instruction: Absolute Call – ACALL Uses an 11-bit address The subroutine must be within the same 2K page . Long Call – LCALL Uses a 16-bit address The subroutine can be anywhere. Both forms push the 16-bit address of PC on the stack and update the stack pointer.
  • 4. Absolute Call – ACALL addr11 This instruction unconditionally calls a subroutine indicated by the address 2 byte instruction : The upper 3-bits of the address combine with the 5-bit opcode to form the 1 st byte and the lower 8-bits of the address form the 2 nd byte Eg. ACALL LOC_SUB If SP=07H initially label “LOC_SUB” is at memory 0567H, then executing instruction at 0230H (PC), SP=09H, internal RAM locations 08H and 09H will contain 32H and 02H respectively and PC=0567H
  • 5. LONG CALL - LCALL addr16 It is a Long call, the subroutine may therefore begin anywhere in the full 64 kB program memory address space 3 byte instruction LCALL LOC_SUB Initially, SP=07H label “LOC_SUB” is at memory 4100H Executing the instruction at 0230H ( PC), SP=09H , internal RAM locations 08H and 09H contain 33H and 02H respectively and PC=4100H
  • 6. RETURN  RET & RETI The 8051 provides 2 forms for the return instruction: Return from subroutine – RET Pop the return address from the stack and continue execution there. Return from ISR – RETI Pop the return address from the stack. Restore the interrupt logic to accept additional interrupts at the same priority level as the one just processed . Continue execution at the address retrieved from the stack. The PSW is not automatically restored.
  • 7. JUMP  SJMP The 8051 provides four different types of unconditional jump instructions: Short Jump – SJMP addr Uses an 8-bit signed offset relative to the 1 st byte of the next instruction . the range of destination allowed is from -128 to+127 bytes from the instruction SJMP RELSRT If the label RELSRT is at program memory location 0120H and the SJMP instruction is located at address 0100H ( PC) ,after executing the instruction, PC=0120H
  • 8. JUMP  LJMP Long Jump – LJMP Uses a 16-bit address . 3 byte instruction capable of referencing any location in the entire 64K of program memory. LJMP FAR_ADR If the label FAR_ADR is at program memory location 3456H the LJMP instruction at location 0120H (PC) After instruction, it loads the PC with 3456H
  • 9. JUMP  AJMP Absolute Jump – AJMP Uses an 11-bit address . 2 byte instruction The 11-bit address is substituted for the lower 11-bits of the PC to calculate the 16-bit address of the target. The location referenced must be within the 2K Byte AJMP NEAR If the label NEAR is at program memory location 0120H , the AJMP instruction at location 0234H (PC) loads the PC with 0120H
  • 10. Indirect Jump This instruction adds the 8-bit unsigned value of the ACC to the 16-bit data pointer and the resulting sum is returned to the PC Neither ACC nor DPTR is altered No flags are affected MOV DPTR, #LOOK_TBL JMP @A + DPTR LOOK_TBL: AJMP LOC0 AJMP LOC1 AJMP LOC2 If the ACC=02H , execution jumps to LOC2 AJMP is a two byte instruction
  • 11. CONDITIONAL JUMP The 8051 supports different conditional jump instructions. ALL conditional jump instructions use an 8-bit address. Jump on Zero – JZ / JNZ Jump if the A == 0 / A != 0 The check is done at the time of the instruction execution. Jump on Carry – JC / JNC Jump if the C flag is set / cleared.
  • 12. CONDITIONAL JUMP Jump on Bit – JB / JNB Jump if the specified bit is set / cleared. Any addressable bit can be specified. Jump if the Bit is set then Clear the bit – JBC Jump if the specified bit is set. Then clear the bit.
  • 13. Compare and Jump if Not Equal – CJNE Compare the magnitude of the two operands and jump if they are not equal. The values are considered to be unsigned. The Carry flag is set / cleared appropriately. CJNE A, direct, rel CJNE A, #data, rel CJNE Rn, #data, rel CJNE @Ri, #data, rel
  • 14. Decrement and Jump if Not Zero – DJNZ Decrement the first operand by 1 and jump to the location identified by the second operand if the resulting value is not zero. DJNZ 20H,LOC1 DJNZ 30H,LOC2 DJNZ 40H,LOC3 If internal RAM locations 20H, 30H and 40H contain the values 01H, 5FH and 16H respectively, the above instruction sequence will cause a jump to the instruction at LOC2 , with the values 00H, 5EH, and 15H in the 3 RAM locations
  • 15. NOP This is the no operation instruction The instruction takes one machine cycle operation time Hence it is useful to time the ON/OFF bit of an output port CLR P1.2 NOP NOP NOP NOP SETB P1.2