Branch Instructions (Program Control) - 2.3.1 | Module 2: Microprocessor Architectures: 8085 and 8086 | Microcontroller
K12 Students

Academics

AI-Powered learning for Grades 8–12, aligned with major Indian and international curricula.

Professionals

Professional Courses

Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.

Games

Interactive Games

Fun, engaging games to boost memory, math fluency, typing speed, and English skills—perfect for learners of all ages.

Interactive Audio Lesson

Listen to a student-teacher conversation explaining the topic in a relatable way.

Introduction to Branch Instructions

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Today we'll discuss branch instructions, which are essential for altering program execution flow within the 8085 microprocessor.

Student 1
Student 1

What exactly do branch instructions do?

Teacher
Teacher

Great question! Branch instructions change the address in the Program Counter (PC), allowing the program to jump to different parts of the code. For example, an unconditional jump using `JMP Adr` simply transfers control to the address specified by `Adr`.

Student 2
Student 2

So there's a jump that happens without any conditions?

Teacher
Teacher

Exactly! This is called an unconditional jump. Condition-based jumps check the status of certain flags before deciding to jump. Can you name one conditional jump instruction?

Student 3
Student 3

Maybe `JC Adr`, which jumps if the Carry Flag is set?

Teacher
Teacher

Perfect! Remember, conditional jumps are crucial for making decisions in code.

Student 4
Student 4

What if I want to call a subroutine? How does that work?

Teacher
Teacher

Good point! To call a subroutine, you'd use the `CALL Adr` instruction, which saves the return address on the stack before jumping. At the end of the subroutine, you'd use `RET` to return back.

Teacher
Teacher

In summary, branch instructions enable dynamic control of code execution flow, allowing for processes like loops and conditional logic.

Types of Branch Instructions

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Let's dive deeper into different types of branch instructions. First, can anyone explain what an unconditional jump does?

Student 1
Student 1

It jumps to a specific address without checking anything, right?

Teacher
Teacher

Yes! Now how about conditional jumps? Can someone describe one of them?

Student 2
Student 2

The `JZ Adr` jumps if the Zero Flag is set.

Teacher
Teacher

You're right! What this does is alter the flow based on whether the last operation resulted in zero. It's a fundamental aspect of logic in programming.

Student 3
Student 3

Are there return instructions like `RET` used for backtracking?

Teacher
Teacher

Absolutely! `RET` pops the last address off the stack, ensuring the program continues execution right where it left off. Very analytical! Now let's summarize today's session.

Teacher
Teacher

In today's session, we explored unconditional jumps, conditional jumps, and return instructions. Each plays a distinct role in program control.

Call and Restart Instructions

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Now, let's discuss call instructions. What do they do?

Student 4
Student 4

They save the address for returning after a subroutine?

Teacher
Teacher

That's correct! Specifically, with the command `CALL Adr`, the PC is pushed onto the stack before it jumps to the subroutine address. Why is that important?

Student 1
Student 1

So the program knows where to come back after it finishes executing the subroutine!

Teacher
Teacher

Exactly! And we also have restart instructions like `RST n` which call specific addresses. Does anyone recall the significance of these instructions?

Student 2
Student 2

They help manage interrupts, right?

Teacher
Teacher

Yes! They're vital for handling routine tasks like resets. Let's wrap up this session.

Teacher
Teacher

Today, we focused on call and restart instructions, seeing how they play essential roles in managing subroutines and interrupts.

Introduction & Overview

Read a summary of the section's main ideas. Choose from Basic, Medium, or Detailed.

Quick Overview

This section deals with branch instructions that alter the flow of program execution in the 8085 microprocessor.

Standard

Branch instructions in the 8085 microprocessor are critical for controlling program flow. This section covers unconditional and conditional jumps, call and return instructions, and restart instructions, shedding light on how the Program Counter (PC) is manipulated to control execution paths.

Detailed

Branch Instructions (Program Control)

Branch instructions play a vital role in altering the flow of program execution in microprocessors, particularly in the 8085 architecture. They influence the Program Counter (PC), determining the next executed instruction based on specified conditions. This section delineates myriad branch instructions, categorized primarily into:

Unconditional Jumps

  • JMP Adr: This instruction makes the program flow unconditionally jump to the address specified by Adr. Essentially, it sets the Program Counter (PC) to Adr, continuing execution from that point without any condition checks.

Conditional Jumps

Conditional jumps evaluate the state of the processor flags, executing the jump only if a given condition based on these flags is met. They include:
- JC Adr: Jump if the Carry Flag is set (CY = 1).
- JNC Adr: Jump if the Carry Flag is clear (CY = 0).
- JZ Adr: Jump if the Zero Flag is set (Z = 1).
- JNZ Adr: Jump if the Zero Flag is clear (Z = 0).
- JP Adr: Jump if the Sign Flag is clear (S = 0), indicating a positive result.
- JM Adr: Jump if the Sign Flag is set (S = 1), indicating a negative result.
- JPE Adr: Jump if the Parity Flag is set (P = 1), indicating even parity.
- JPO Adr: Jump if the Parity Flag is clear (P = 0), indicating odd parity.

Call Instructions

These instructions enable program control to transfer to subroutines. They save the return address onto the stack before jumping. Key variants include:
- CALL Adr: Unconditionally calls the subroutine at address Adr.
- CC Adr, CNC Adr, CZ Adr, and many others function similarly to conditional jumps but are specifically designed for subroutine calls.

Return Instructions

Once a subroutine is complete, return instructions retrieve addresses from the stack to resume program execution. Examples include:
- RET: Returns unconditionally from a subroutine.
- RC, RNC, RZ, and others specify return conditions based on corresponding flags.

Restart Instructions (RST)

Specially designed for handling interrupts, these single-byte instruction calls fixed memory locations based on their number. For instance, RST 0 calls the address 0000H, and RST 1 calls 0008H, and so forth.

In summary, mastering branch instructions is fundamental for programming on the 8085 microprocessor, as they allow for dynamic control over program execution, enabling subroutines, loops, and conditional processing.

Audio Book

Dive deep into the subject with an immersive audiobook experience.

Unconditional Jumps

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Unconditional Jumps:

  • JMP Adr: Jump unconditionally to the 16-bit Adr. (Loads Adr into PC).
  • Numerical Example: JMP START. Program execution immediately transfers to the instruction labeled START.

Detailed Explanation

Unconditional jumps are instructions that redirect the program's execution flow to a new address without any conditions. The command 'JMP Adr' tells the microprocessor to load the specified address into the Program Counter (PC), which determines the next instruction to be executed. For example, if we use 'JMP START', the program will immediately go to the part of the code identified by 'START', regardless of any flags or conditions.

Examples & Analogies

Think of this as a train ride where the train conductor makes a decisive choice to go straight to a different station without checking for any signals. No matter what the previous instructions were, the train (program execution) directly changes its path to reach the 'START' station.

Conditional Jumps

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Conditional Jumps:

  • These instructions check the status of a specific flag and jump only if the condition is met. If not, execution continues sequentially.
  • JC Adr: Jump if Carry Flag is Set (CY=1).
  • JNC Adr: Jump if No Carry Flag (CY=0).
  • JZ Adr: Jump if Zero Flag is Set (Z=1).
  • JNZ Adr: Jump if No Zero Flag (Z=0).
  • JP Adr: Jump if Plus (Sign Flag S=0).
  • JM Adr: Jump if Minus (Sign Flag S=1).
  • JPE Adr: Jump if Parity Even (P=1).
  • JPO Adr: Jump if Parity Odd (P=0).

Detailed Explanation

Conditional jumps allow the program to make decisions based on the current status of flags, which are indicators of the results of previous operations. For example, 'JC Adr' will only execute the jump if the Carry Flag is set, meaning the last operation resulted in a carry. If the condition is not satisfied, the program will move to the next instruction in line rather than jumping. This ability adds flexibility and control to how the program executes, enabling different paths or outcomes based on dynamic situations.

Examples & Analogies

Imagine you're playing a game where you only move to a special spot (like a treasure chest) if you have enough coins. If you don't have enough, you just stay where you are and continue playing. Similarly, conditional jumps check specific criteria (like having enough coins) before deciding whether to move to a new part of the code (the treasure spot).

Call Instructions

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Call Instructions:

  • Used to transfer control to a subroutine. The return address (address of the instruction after the CALL) is saved on the stack.
  • CALL Adr: Unconditionally call subroutine at 16-bit Adr. (Pushes PC onto stack, then loads Adr into PC).
  • CC Adr: Call if Carry (CY=1).
  • CNC Adr: Call if No Carry (CY=0).
  • CZ Adr: Call if Zero (Z=1).
  • CNZ Adr: Call if No Zero (Z=0).
  • CP Adr: Call if Plus (S=0).
  • CM Adr: Call if Minus (S=1).
  • CPE Adr: Call if Parity Even (P=1).
  • CPO Adr: Call if Parity Odd (P=0).

Detailed Explanation

Call instructions are utilized to invoke subroutines, which are essentially smaller programs or functions within the main program. When a 'CALL Adr' instruction is executed, the address of the next instruction (the return point) is placed on the stack, and the Program Counter (PC) is updated to point to the subroutine's starting address. This mechanism allows for organized coding practices, with specific tasks encapsulated in subroutines that can be reused. The return from the subroutine is typically accomplished with a 'RET' instruction.

Examples & Analogies

Consider calling a friend to help you with a task. You tell them your address (the subroutine address), and importantly, you remember the task you were doing before they arrived (the return address). After your friend helps you, you can return to your original task, just as the program goes back to the point after the subroutine once it's done executing.

Return Instructions

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Return Instructions:

  • Used to return from a subroutine. The return address is retrieved from the stack and loaded into PC.
  • RET: Unconditionally return from subroutine. (Pops PC from stack).
  • RC: Return if Carry (CY=1).
  • RNC: Return if No Carry (CY=0).
  • RZ: Return if Zero (Z=1).
  • RNZ: Return if No Zero (Z=0).
  • RP: Return if Plus (S=0).
  • RM: Return if Minus (S=1).
  • RPE: Return if Parity Even (P=1).
  • RPO: Return if Parity Odd (P=0).

Detailed Explanation

Return instructions provide a mechanism for exiting from a subroutine and continuing execution from where the subroutine was called. The 'RET' instruction pops the previously saved return address from the stack into the Program Counter (PC), effectively sending control back to that point in the main program. This allows for nesting of subroutines and complex program structures without losing track of where to return after completing a task.

Examples & Analogies

Think of a student who leaves their classroom to visit the library. They have a note with the classroom's location (the return address). After completing their task in the library, they refer back to the note to find their way back to the classroom. In programming, the 'RET' instruction works similarly, ensuring that the execution flow returns to the point right after the subroutine was called.

Restart Instructions (RST)

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Restart Instructions (RST):

  • Special single-byte call instructions primarily used for interrupts. They implicitly call a fixed memory location based on the RST number.
  • RST n (n = 0 to 7): Calls subroutine at fixed vector address (n×8).
  • RST 0: Calls 0000H (typically used for reset).
  • RST 1: Calls 0008H.
  • ...
  • RST 7: Calls 0038H.

Detailed Explanation

Restart instructions (RST) are unique and simple instructions that allow for quick access to predefined subroutines, often used for handling interrupts. Each RST instruction corresponds to a specific fixed memory address, multiplying the given number by 8 to compute the destination for the call. This provides a systematic way to handle certain types of events, making it efficient for responses to interrupts. These instructions serve as shortcuts to specific locations in memory, improving response time for interrupt-driven operations.

Examples & Analogies

Imagine a fire alarm that goes off in a building. When it happens, there are predetermined procedures to follow, like evacuating or checking for safety — each linked to specific signals or alarms. Similarly, the RST instructions provide a pathway to react to specific situations in the program, allowing the microprocessor to efficiently handle events.

Definitions & Key Concepts

Learn essential terms and foundational ideas that form the basis of the topic.

Key Concepts

  • Unconditional Jumps: Alter execution flow directly to specified address without conditions.

  • Conditional Jumps: Execution depends on flag states, allowing for program logic.

  • Call Instructions: Enable subroutine calls and store return address.

  • Return Instructions: Facilitate returning from subroutines to previous execution point.

  • Restart Instructions: Used for handling interrupts and executing fixed memory calls.

Examples & Real-Life Applications

See how the concepts apply in real-world scenarios to understand their practical implications.

Examples

  • Using JMP 1000H transfers execution to address 1000H instantly.

  • Calling a subroutine with CALL 2000H saves the return address on the stack for later use.

Memory Aids

Use mnemonics, acronyms, or visual cues to help remember key information more easily.

🎵 Rhymes Time

  • Jump, jump, without a care, to an address far and rare.

📖 Fascinating Stories

  • Imagine a traveler who uses a special map, the CALL instruction, to navigate to a city (subroutine) while marking where they came from (return address) on the back of the map.

🧠 Other Memory Gems

  • Jumps Conditional Like Cows (JC, JNC, JZ, JNZ) - remember the conditional jumps.

🎯 Super Acronyms

C.J.R (Call, Jump, Return) - the three main components of branch instructions.

Flash Cards

Review key concepts with flashcards.

Glossary of Terms

Review the Definitions for terms.

  • Term: JMP

    Definition:

    An instruction that causes an unconditional jump to the specified address in the program.

  • Term: JC

    Definition:

    A conditional jump instruction that occurs if the Carry Flag is set.

  • Term: JZ

    Definition:

    A conditional jump instruction that occurs if the Zero Flag is set.

  • Term: CALL

    Definition:

    An instruction that calls a subroutine and saves the return address.

  • Term: RET

    Definition:

    An instruction that returns from a subroutine, restoring the previous address from the stack.

  • Term: RST

    Definition:

    Instructions used to handle interrupts, calling predefined memory addresses.