Program 3: Basic Arithmetic Operation (Subtraction with Borrow) - 4.3 | EXPERIMENT NO. 1:Introduction to 8085 Microprocessor - Architecture and Basic Operations | Microcontroller Lab
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.

Understanding Subtraction in 8085

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Today, we're going to dive into subtraction using the 8085 microprocessor. Can anyone tell me what happens when we subtract a larger number from a smaller number?

Student 1
Student 1

I think the result would be negative, right?

Teacher
Teacher

Exactly! And in the 8085 architecture, this situation generates a borrow. This is represented in the Carry Flag. Does anyone know what we mean by the Carry Flag?

Student 2
Student 2

Isn't it the flag that tells us if there's been a carry out in an addition operation?

Teacher
Teacher

That's right! The same applies here. In subtraction, if there's a borrow, the Carry Flag will be set to 1. Can anyone recall how we perform the subtraction operation using assembly language?

Student 3
Student 3

We use the SUB instruction, right?

Teacher
Teacher

Yes! For example, if A has **05H** and B has **10H**, executing `SUB B` will set A to **F5H**. What does that tell us about the result?

Student 4
Student 4

It shows that we have a negative result because **F5H** in 2's complement indicates we couldn't perform that operation without borrowing!

Teacher
Teacher

Exactly! Let's remember that crucial point about borrow and the Carry Flag today.

Analyzing Flag Register Status

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Now, let's analyze the flags after a subtraction operation. When we execute `SUB B` where A is **05H** and B is **10H**, what would happen to each flag?

Student 1
Student 1

The Sign Flag would be set to 1 because the result is negative.

Teacher
Teacher

Correct! And how about the Zero Flag?

Student 2
Student 2

It would be 0 since the result is not zero.

Teacher
Teacher

Right! Any thoughts on the Auxiliary Carry Flag?

Student 3
Student 3

It should be 0 as there's no intermediate borrow.

Teacher
Teacher

Great observation! Finally, what about the Parity Flag?

Student 4
Student 4

It would be 0 as well, since there are five 1s in the binary representation of **F5H**, which is odd.

Teacher
Teacher

Excellent! Always remember to check these flags after any arithmetic operation as they provide crucial insights.

Practical Implementation: Example Program for Subtraction

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Let's look at a sample program. We will set up our registers, perform the subtraction and observe the memory states. How do we begin?

Student 1
Student 1

We'll start by loading values into the Accumulator and Register B!

Teacher
Teacher

Exactly! We'll use `MVI A, 05H` and `MVI B, 10H`. What’s next?

Student 2
Student 2

Then we execute `SUB B`, right?

Teacher
Teacher

Correct! After this, we store the result in memory with `STA 2070H`. What should we observe in Memory location 2070H?

Student 3
Student 3

It should contain **F5H** after running the program.

Teacher
Teacher

Exactly! And what will the program counter show?

Student 4
Student 4

It will show **2009H**, as it points to the next instruction after HALT.

Teacher
Teacher

Great job! This is a clear understanding of how to work with subtraction in 8085. Remember, careful observation of the flags and memory is crucial in microprocessor programming!

Introduction & Overview

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

Quick Overview

This section covers the implementation of subtraction operations using the 8085 microprocessor, emphasizing the concepts of borrow and flag status after arithmetic operations.

Standard

The section focuses on performing basic subtraction using the 8085 microprocessor, including the introduction of borrow when subtracting a larger number from a smaller one. It also provides practical examples, explanations of registers, memory storage, and expected flag outcomes that indicate the result's nature.

Detailed

Detailed Summary

This section describes subtraction operations carried out using the 8085 microprocessor, specifically focusing on the use of the SUB instruction. It outlines how to manage the process of subtracting larger numbers from smaller ones, resulting in the concept of borrow, which is essential for understanding how computations affect the flags in the Flag Register.

Key Operations in 8085:

  1. Subtraction: The core instruction discussed is SUB, which subtracts the content of a specified register from the Accumulator.
  2. Example: If the Accumulator (A) contains 05H and register B contains 10H, after executing SUB B, the contents of A become F5H, which indicates a borrow has occurred, reflecting the behavior of 2's complement representation in binary.
  3. Flag Register States: Post subtraction, the flags provide valuable insights. In the instance above,
  4. Sign Flag (S) is set to 1, indicating a negative result.
  5. Carry Flag (C) is also set, indicating that a borrow occurred.
  6. Other flags, like Zero (Z), Auxiliary Carry (AC), and Parity (P), also provide meaningful insights into the result.

This section serves to illustrate the concept of subtraction using assembly language, coupled with practical examples and flow analysis through registers, enhancing the reader's familiarity with the workings of the 8085 microprocessor.

Audio Book

Dive deep into the subject with an immersive audiobook experience.

Objective of the Program

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Objective: To subtract a larger number from a smaller number (05H - 10H), store the result in memory (2070H), and observe the specific flag status, particularly the Carry/Borrow flag.

Detailed Explanation

The goal of this program is to perform a subtraction operation where a larger number (10H) is subtracted from a smaller number (05H). In digital systems, when this occurs, it results in a negative value. The result of this operation will be stored in a memory location (2070H), and we will also examine the status flags to see how the CPU interprets this borrowing due to the negative result.

Examples & Analogies

Think of this like trying to withdraw more money from your bank account than you have. If you have $5 but want to withdraw $10, you end up 'borrowing' $5 from the bank. In the same way, when the microprocessor tries to calculate 05H - 10H, it ends up needing to borrow to execute this operation, which is reflected in the Carry flag.

Assembly Code for Subtraction with Borrow

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Assembly Code:

; Program to demonstrate subtraction and flag changes (with borrow)
; Starting Address: 2000H
ORG 2000H
MVI A, 05H ; Load Accumulator A with immediate data 05H (A = 05H)
MVI B, 10H ; Load Register B with immediate data 10H (B = 10H)
SUB B ; Subtract content of Register B from Accumulator A (A = A - B)
STA 2070H ; Store content of Accumulator A into memory location 2070H
HLT ; Halt processor execution

Detailed Explanation

This chunk presents the assembly code written for the 8085 microprocessor. It begins at memory address 2000H. The instructions are as follows:
1. ORG 2000H - This directive tells the assembler where to start placing the program in memory.
2. MVI A, 05H - This instruction loads the immediate value of 05H into the Accumulator (A).
3. MVI B, 10H - This instruction loads the value of 10H into register B.
4. SUB B - Here, the content of register B (10H) is subtracted from the value in the Accumulator (05H).
5. STA 2070H - The result of the subtraction (which will involve borrowing) is stored in memory address 2070H.
6. HLT - This instruction halts the processor execution after executing all prior commands.

Examples & Analogies

Entering this code is similar to how you might write a recipe. You list the ingredients and instructions to get the desired dish. In this case, the ingredients are the values we need (05H and 10H), and the instructions are how to process these values to get our final result, which in this case involves borrowing.

Memory Layout for the Program

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Memory Layout:
| Address | Hex Code | Instruction |
| :------ | :------- | :------------------ |
| 2000H | 3E | MVI A, 05H |
| 2001H | 05 | |
| 2002H | 06 | MVI B, 10H |
| 2003H | 10 | |
| 2004H | 90 | SUB B |
| 2005H | 32 | STA 2070H |
| 2006H | 70 | |
| 2007H | 20 | |
| 2008H | 76 | HLT |

Detailed Explanation

The memory layout details how each instruction is represented in memory as opcodes. Each row corresponds to a memory address and shows what instruction is stored there:
- At 2000H, the opcode for loading 05H into the Accumulator is stored (3E).
- 05 at 2001H represents the immediate data.
- At 2002H, the opcode for loading 10H into register B is (06), followed by the data (10H) at 2003H.
- The opcode for the subtraction operation (90) is stored at 2004H, and its result is stored at address 2070H.

Examples & Analogies

Imagine a filing cabinet where each drawer represents a memory address. Each drawer holds a piece of information (an opcode or operand) that helps you complete a task. Just as each task in your day might be planned out in a notebook, the memory layout structures our program clearly so that the microprocessor can follow the steps without confusion.

Expected States After Execution

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Expected Register and Memory States (After Execution of HLT):
● A Register: F5H (05H - 10H = F5H in 8-bit 2's complement, representing -11 decimal)
● B Register: 10H
● Memory Location 2070H: F5H
● Program Counter (PC): 2009H
● Flag Register Status (after SUB B where A=05H, B=10H, Result A=F5H):
○ S (Sign Flag): 1 (Result F5H is negative, MSB is 1)
○ Z (Zero Flag): 0 (Result F5H is not zero)
○ AC (Auxiliary Carry Flag): 0 (No intermediate borrow)
○ P (Parity Flag): 0 (Result F5H = 11110101b, has five '1' bits, which is odd parity)
○ C (Carry Flag): 1 (Carry flag is set, indicating a borrow occurred from the most significant bit, which happens when a larger number is subtracted from a smaller one).

Detailed Explanation

After executing the program, multiple results can be observed:
- The Accumulator results in F5H, reflecting the negative outcome of the subtraction which is stored in 2's complement.
- Register B will still hold the original value of 10H, while at memory location 2070H, we expect to find F5H, the result of the subtraction.
- The Program Counter increments to 2009H, showing where the next instruction would execute if there were one. The flag register will reflect:
- Sign Flag = 1, indicating that the result is negative.
- Zero Flag = 0, as the result is not zero.
- Carry Flag = 1 due to the borrow during the operation, marking this occurrence distinctly.

Examples & Analogies

Consider grading a test where a student had a score of 5, but they needed at least 10 to pass. The system will reflect a failure (negative score) in the grading book (Accumulator), showing that they owe (borrow) points to reach the passing score. Just like the flags in our program display key outcomes of the operation, the grading reflects whether the student has passed or failed.

Definitions & Key Concepts

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

Key Concepts

  • Subtraction Operation: Using the SUB instruction to perform subtraction in 8085.

  • Borrow: Borrow occurs when you subtract a larger number from a smaller number.

  • Flag Register: Holds flags indicating the results of arithmetic operations.

Examples & Real-Life Applications

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

Examples

  • Example of a subtraction operation using SUB instruction: A = 05H, B = 10H results in A = F5H.

  • Flag status after subtraction of 05H - 10H: S = 1, C = 1, Z = 0.

Memory Aids

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

🎵 Rhymes Time

  • To subtract a larger from the small, watch the borrow flag, it shows it all!

📖 Fascinating Stories

  • Once there was a brave little number named A, who attempted to take away 10 from 5 but realized it couldn't, leading it to seek help from the mysterious borrow, showing up as F5H!

🧠 Other Memory Gems

  • Remember: Subtracting small from large (S) means a Borrow, resulting in a Carry Flag (BC).

🎯 Super Acronyms

SFB (Subtracting For Borrow) helps remember to check flags after!

Flash Cards

Review key concepts with flashcards.

Glossary of Terms

Review the Definitions for terms.

  • Term: Accumulator

    Definition:

    A register in the 8085 microprocessor where arithmetic and logic results are stored.

  • Term: Carry Flag

    Definition:

    A flag that indicates if there is a carry from the most significant bit during arithmetic operations.

  • Term: Borrow

    Definition:

    The concept used in subtraction to indicate when more is being subtracted than is present.

  • Term: Flag Register

    Definition:

    A special register that holds the status flags resulting from arithmetic and logical operations.

  • Term: Subtraction

    Definition:

    An arithmetic operation to determine the difference between two numbers.