Arithmetic Instructions - 2.2.2 | 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 Arithmetic Instructions

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Today, we will explore arithmetic instructions in the 8085 microprocessor. Can anyone tell me what operations fall under arithmetic instructions?

Student 1
Student 1

I think they include addition and subtraction.

Teacher
Teacher

Yes, that's correct! Arithmetic instructions primarily handle addition, subtraction, increment, and decrement. Let's break down the addition instructions first.

Student 2
Student 2

How does the processor know if the addition goes beyond the maximum value?

Teacher
Teacher

Great question! The Carry Flag is set if there is an overflow during addition. This is important for handling multi-byte calculations. Remember A + B = C; if there's an overflow, CY will be 1!

Student 3
Student 3

Can you explain the `ADD R` instruction with an example?

Teacher
Teacher

Absolutely! If A contains 10H and we add B, if B contains 05H, after `ADD B`, A becomes 15H. The Carry flag, AC, and other flags will be updated accordingly.

Teacher
Teacher

To recap, arithmetic instructions are crucial for data processing in the 8085, directly influencing the Carry and Zero flags, which can determine the flow of a program.

Subtraction and Increment/Decrement Instructions

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Now, let's discuss subtraction. The instruction `SUB R` subtracts a specified register from the Accumulator. Who can remind me of the flags affected during subtraction?

Student 1
Student 1

The Zero, Sign, and Carry flags!

Teacher
Teacher

Right! After a subtraction operation, if the result is negative, the Sign Flag will be set. What about increment and decrement instructions?

Student 4
Student 4

They increase or decrease the value, right? And they affect flags too?

Teacher
Teacher

Exactly! `INR` increases the value by 1 and `DCR` decreases it. Both affect the Zero flag if the result is zero but do not affect the Carry flag. For example, if B is 0FH, and we perform `INR B`, B will become 10H.

Teacher
Teacher

To summarize, understanding how these instructions affect flags is crucial for implementing logical conditions in your code.

Decimal Adjust and Double Addition

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Lastly, let's look at special instructions like `DAA` and `DAD`. Does anyone know why we use `DAA`?

Student 2
Student 2

Isn't it to correct results after an addition operation to get valid BCD?

Teacher
Teacher

That's correct! `DAA` adjusts the Accumulator to ensure it holds valid BCD digits. Can someone describe `DAD`?

Student 3
Student 3

It adds a register pair to the H-L register pair, right?

Teacher
Teacher

Exactly! It’s often used for adding numbers larger than what a single register can hold without affecting most flags except CY. Remember, these operations are essential for manipulating numerical data effectively.

Teacher
Teacher

In conclusion, these arithmetic instructions enable the processor to perform complex calculations and manage data efficiently. Always observe the flags for better flow control in your programs.

Introduction & Overview

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

Quick Overview

This section covers the arithmetic instructions of the 8085 microprocessor, detailing how they perform basic mathematical operations and their effects on various flags.

Standard

In this section, we explore the arithmetic instructions available in the 8085 instruction set. These instructions perform addition, subtraction, incrementing, and decrementing operations. Importantly, they also affect the status flags, which provide feedback on the results of these operations, crucial for conditional programming.

Detailed

Arithmetic Instructions in the 8085 Microprocessor

The 8085 microprocessor supports several arithmetic instructions that allow it to perform basic mathematical calculations such as addition, subtraction, incrementing, and decrementing numbers stored in registers or memory. Understanding these instructions is critical as they manipulate data and influence the processor's status flags, which indicate the results of operations and control program flow.

Key Arithmetic Instructions

  1. Addition Instructions: These include:
  2. ADD R: Adds the content of a specified register R to the Accumulator, storing the result in the Accumulator.
  3. ADD M: Adds content from a memory location (pointed by H-L) to the Accumulator.
  4. ADI Data: Adds an immediate 8-bit data value to the Accumulator.
  5. ADC R/M: Adds content from a register or memory along with the Carry flag.
  6. Subtraction Instructions: Similar to addition, subtraction instructions are:
  7. SUB R: Subtracts the content of a register R from the Accumulator.
  8. SUB M: Subtracts content from memory pointed by H-L from the Accumulator.
  9. SUI Data: Subtracts immediate data from the Accumulator.
  10. SBB R/M: Subtracts register or memory content, along with the Borrow flag.
  11. Increment/Decrement Operations: Increments or decrements values in registers or memory without affecting the Carry flag, including INR R/M and DCR R/M.
  12. Double Addition: The DAD Rp instruction adds the content of a register pair to the H-L register pair without affecting most flags except the Carry flag.
  13. Decimal Adjust: The DAA instruction adjusts the Accumulator value to form a valid BCD after an addition operation.

Flags Affected by Arithmetic Operations

The execution of these arithmetic operations directly affects the flags in the Flag Register:
- S (Sign Flag): Indicates if the result is negative.
- Z (Zero Flag): Set if the result is zero.
- AC (Auxiliary Carry Flag): Indicates carry between nibbles.
- P (Parity Flag): Reflects the parity of the result.
- CY (Carry Flag): Set if there’s a carry out from the most significant bit.

These operations are fundamental to data manipulation in programming and necessitate careful consideration of the flags resulting from their execution.

Audio Book

Dive deep into the subject with an immersive audiobook experience.

Introduction to Arithmetic Instructions

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

These instructions perform addition, subtraction, increment, and decrement operations. They affect the flags (S, Z, AC, P, CY) based on the result.

Detailed Explanation

Arithmetic instructions are essential commands in computer programming that allow the microprocessor to perform mathematical operations such as addition, subtraction, incrementing, and decrementing values. Each operation impacts specific flags in the flag register. For example, after an addition, the Sign flag (S) indicates if the result is negative, the Zero flag (Z) shows if the result is zero, and the Carry Flag (CY) tells if there was a carry out from the most significant bit.

Examples & Analogies

Think of arithmetic instructions like a calculator. When you perform a calculation like 2 + 3, the calculator not only gives you a result of 5 but also displays an indicator if the result is zero or negative. Just like the calculator keeps track of these different states, the microprocessor uses flags to remember the results of its operations.

Addition Operations

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Addition:
- ADD R: Add content of register R to Accumulator. Result in A.
- Numerical Example: If A=10H, B=05H, after ADD B, A will be 15H.
- Flags: Z=0, P=1 (even parity for 15H=00010101B), CY=0, AC=0, S=0.
- ADD M: Add content of memory pointed by H-L to Accumulator. Result in A.
- ADI Data: Add immediate 8-bit Data to Accumulator. Result in A.
- ADC R: Add content of register R to Accumulator with Carry flag. (A = A + R + CY).
- ADC M: Add content of memory pointed by H-L to Accumulator with Carry flag.
- ACI Data: Add immediate 8-bit Data to Accumulator with Carry flag.

Detailed Explanation

Addition instructions in the 8085 microprocessor allow the addition of numbers either stored in registers or in memory. The ADD R instruction adds the value in register R to the value stored in the Accumulator (A). The result updates the Accumulator. Similar operations can be performed with memory locations using ADD M. Operations like ADC and ACI include the Carry Flag in the calculation, accounting for previous arithmetic operations that may have resulted in a carry.

Examples & Analogies

Consider filling a container with water (Accumulator) and adding different measuring cups of water (registers). Each time you pour water from a cup into the container, you are effectively adding that amount to your total. If you have a cup full of water and a little spill (carry), you want to remember that for the next time you pour; this is what the Carry Flag does!

Subtraction Operations

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Subtraction:
- SUB R: Subtract content of register R from Accumulator. Result in A. (A = A - R).
- Numerical Example: If A=10H, B=05H, after SUB B, A will be 0BH.
- Flags: Z=0, P=1 (even parity for 0BH=00001011B), CY=0 (no borrow), AC=0, S=0.
- SUB M: Subtract content of memory pointed by H-L from Accumulator.
- SUI Data: Subtract immediate 8-bit Data from Accumulator.
- SBB R: Subtract content of register R from Accumulator with Borrow (A = A - R - CY).
- SBB M: Subtract content of memory pointed by H-L from Accumulator with Borrow.
- SBI Data: Subtract immediate 8-bit Data from Accumulator with Borrow.

Detailed Explanation

In subtraction, the SUB instruction subtracts the value held in a specified register or memory from the value in the Accumulator. Similar to addition, this operation updates the Accumulator with the result. The presence of the Carry Flag indicates whether the last operation produced a borrow, which can be factored into subsequent calculations with instructions like SBB.

Examples & Analogies

Imagine you have some money in your wallet (Accumulator) and you buy a snack (the value in R or memory). Subtracting the cost from the money in your wallet gives you a new, smaller amount, and if you weren’t fully prepared for the expense, that slight shortfall (borrow) will need to be taken into account when you next decide to buy something.

Increment and Decrement Operations

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Increment/Decrement:
- INR R: Increment content of register R by 1. (Affects all flags except CY).
- Numerical Example: If B=0FH, after INR B, B will be 10H.
- DCR R: Decrement content of register R by 1. (Affects all flags except CY).
- INR M: Increment content of memory pointed by H-L by 1. (Affects all flags except CY).
- DCR M: Decrement content of memory pointed by H-L by 1. (Affects all flags except CY).
- INX Rp: Increment content of register pair Rp (BC, DE, HL) by 1. (Does NOT affect any flags).
- Numerical Example: If HL=1FFFH, after INX H, HL will be 2000H.
- DCX Rp: Decrement content of register pair Rp by 1. (Does NOT affect any flags).

Detailed Explanation

The increment and decrement instructions allow for quick adjustments to register values. Incrementing increases the register by one, while decrementing reduces it by one. Most of these operations affect the flag register, helping keep track of the states resulting from these operations, except for the DCX and INX operations, which don't affect any flags.

Examples & Analogies

Think of incrementing and decrementing like adjusting the volume on a speaker. Turning the knob (increment) makes the sound louder, while turning it back (decrement) makes it quieter. Just as you might remember the last volume level you set (state of flags), incrementing and decrementing in a program keeps track of your 'volume level' in the form of register values.

Double Addition and DAA

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Double Addition:
- DAD Rp: Add content of register pair Rp (BC, DE, HL) to H-L pair. Result in H-L. (Only affects CY flag).
- Numerical Example: If HL=1000H, DE=2000H, after DAD D, HL will be 3000H.
- Decimal Adjust Accumulator (DAA):
- DAA: Adjusts the content of the Accumulator to form a two-digit BCD number after an addition operation. It uses the Carry and Auxiliary Carry flags.
- Numerical Example: If A=18H and we add 23H (BCD numbers) without DAA: ADD A, #23H -> A=3BH. After DAA, A will be 41H (because 18+23 = 41 decimal).

Detailed Explanation

Double addition allows for efficient addition of larger numerical values by adding register pairs to a combined register like H-L. The DAA instruction adjusts the result in the Accumulator to ensure it forms valid Binary Coded Decimal (BCD) representations, aiding calculations that require precise numeral formatting.

Examples & Analogies

Consider packing two boxes of goods where each box's weight needs to be considered together (double addition). After calculating the total weight, you realize it needs to be presented in a specific format for display – similar to how DAA reformats the accumulator’s result for proper numerical representation.

Definitions & Key Concepts

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

Key Concepts

  • Arithmetic Instructions: Operations like addition, subtraction, incrementing, and decrementing numbers stored in registers or memory.

  • Flags: Status indicators that provide information about the results of arithmetic operations, affecting program flow.

Examples & Real-Life Applications

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

Examples

  • If A = 10H and B = 05H, after executing 'ADD B', A = 15H.

  • If A = 10H, after executing 'SUB B' with B = 05H, A = 0BH.

Memory Aids

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

🎵 Rhymes Time

  • Add it up, clear and neat, keep those flags for a treat!

📖 Fascinating Stories

  • Once upon a time, in the land of registers, lived the Accumulator. With each addition and subtraction, he kept track of his values using the wise flags, like Sign and Zero!

🧠 Other Memory Gems

  • Remember the flags with ‘ZAPS’: Zero, Auxiliary Carry, Parity, Sign

🎯 Super Acronyms

Use 'DAA' for Decimal Adjustments After Addition.

Flash Cards

Review key concepts with flashcards.

Glossary of Terms

Review the Definitions for terms.

  • Term: ADD

    Definition:

    An instruction to add the contents of a register or memory location to the Accumulator.

  • Term: SUB

    Definition:

    An instruction to subtract the contents of a register or memory location from the Accumulator.

  • Term: INR

    Definition:

    An instruction to increment the value of a register or memory location by 1.

  • Term: DCR

    Definition:

    An instruction to decrement the value of a register or memory location by 1.

  • Term: DAA

    Definition:

    An instruction to adjust the value in the Accumulator to form a valid BCD number after an addition.

  • Term: DAD

    Definition:

    An instruction to add the contents of a register pair to the H-L register pair.

  • Term: Carry Flag (CY)

    Definition:

    A flag that indicates a carry out from the most significant bit during arithmetic operations.

  • Term: Zero Flag (Z)

    Definition:

    A flag that is set if the result of an operation is zero.

  • Term: Sign Flag (S)

    Definition:

    A flag that indicates if the result of an operation is negative.