Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Practice Problems
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Data Science
  • Machine Learning
  • Courses
  • Linux
  • DevOps
  • SQL
  • Web Development
  • System Design
  • Aptitude
  • GfG Premium
Open In App
Next Article:
Conditional Branch Instructions in AVR Microcontroller
Next article icon

Conditional Branch Instructions in AVR Microcontroller

Last Updated : 24 Sep, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
Conditional branch instructions are the set of instructions that is used to branch out of a loop. We will discuss these instructions for the AVR micro-controller. To understand these instructions, first, we need to know about the registers in the AVR micro-controller.
  1. Status Register (SReg) :
    • It is the flag register in the AVR micro-controller.
    • It is a 8 - bit register. Only 6 of these 8 bits are called conditional flags. They are C, Z, N, V, S, H.
    • The value of these bits indicates some conditions that result after the execution of an instruction.
  2. C - Carry Flag :
    • This flag is set whenever there is a carryout from the D7 bit.
    • This flag bit is affected after an 8-bit addition or subtraction.
  3. Z - Zero Flag :
    • The zero flag reflects the result of an arithmetic or logic operation.
    • If the result is zero, then Z = 1. Therefore, Z = 0 if the result is not zero.
  4. N - Negative Flag :
    • Binary representation of signed numbers uses D7 as the sign bit.
    • The negative flag reflects the result of an arithmetic operation. If the D7 bit of the result is zero.
    • Then N = 0 and the result is positive. If the D7 bit is one, then N = 1 and the result is negative.
  5. V - Overflow Flag :
    • This flag is set whenever the result of a signed number operation is too large.
    • Causing the high-order bit to overflow into the sign bit.
  6. S - Sign Flag :
    • This flag is the result of Exclusive-ORing of N and V flags.
  7. H - Half Carry Flag :
    • If there is a carry from D3 to D4 during an ADD or SUB operation, this bit is set; otherwise, it is cleared.
    • This flag bit is used by instructions that perform BCD (binary coded decimal) arithmetic.
The following table shows a few branch loop instructions :
Instruction Explanation Flag Status
BREQ Branch if equal Branch if Z = 1
BRNE Branch if not equal Branch if Z = 0
BRSH Branch if same or higher Branch if C = 0
BRLO Branch if lower Branch if C = 1
BRLT Branch if less than (signed) Branch if S = 1
BRGE Branch if greater than or equal (signed) Branch if S = 0
BRVS Branch if Overflow flag set Branch if V = 1
BRVC Branch if Overflow flag clear Branch if V = 0

Next Article
Conditional Branch Instructions in AVR Microcontroller

K

kunalsg18elec
Improve
Article Tags :
  • Electronics Engineering
  • microprocessor

Similar Reads

    Branch Instructions in AVR Microcontroller
    In this article, we will be discussing looping in AVR and branch instructions, both Conditional and Unconditional. Looping in AVR : A repeated operation or a set of instructions is known as a loop in programming. It is one of the most fundamental techniques which comes in very handy in writing code.
    3 min read
    Arithmetic instructions in AVR microcontroller
    Arithmetic Instructions are the instructions which perform basic arithmetic operations such as addition, subtraction, multiplication, etc. AVR micro-controller has 2 operands which are actually registers that hold the data. The left register is the source register while the right one is the source r
    2 min read
    Data Transfer instructions in AVR microcontroller
    Data transfer instructions are the instructions that are used to transfer data into micro-controller. These instructions can be used to transfer data from: Register to Register : In register-to-register transfer, data is transfer from one register to another register. Consider an example where you h
    3 min read
    Logical Instructions in AVR Microcontroller
    Logical Instructions are the instructions which perform basic arithmetic operations such as AND, OR, XOR, etc. In AVR micro-controller, the destination operand is always a register. The following table shows the logical instructions : Instruction Operand Explanation Example AND D, S D = D AND S Perf
    2 min read
    Branching instructions in 8085 microprocessor
    Branching instructions refer to the act of switching execution to a different instruction sequence as a result of executing a branch instruction. The three types of branching instructions are: Jump (unconditional and conditional) Call (unconditional and conditional) Return (unconditional and conditi
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences