

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
8085 program to subtract two consecutive bytes of an array
Here we will see how we can subtract two consecutive elements in an array using 8085.
Problem Statement
Write 8085 program to subtract two consecutive elements of an array and store them in the same location. The results will be placed at the same location from where they are taken. The numbers are stored from location 8001. The size of array is stored at 8000.
Discussion
Here we will solve this problem by using one subroutine. That will subtract two consecutive numbers and stored them into correct position. That subroutine will be called multiple times to subtract all consecutive pairs. The task will be followed half of the number of elements. So we are taking the count, then rotate it to the right to make it half. We are rotating through carry. if the carry is already high it may store different result, so we are clearing the carry by using STC and CMC instructions.
Input
Address | Data |
---|---|
… | … |
8000 | 0A |
8001 | E9 |
8002 | D3 |
8003 | AD |
8004 | 61 |
8005 | 2A |
8006 | 1F |
8007 | 5D |
8008 | 26 |
8009 | A9 |
800A | 35 |
… | … |
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 21, 00, 80 | | LXI H,8000 | Point to get array size |
F003 | 7E | | MOV A,M | load array size into memory |
F004 | 37 | | STC | set carry flag |
F005 | 3F | | CMC | complement carry flag |
F006 | 0F | | RRC | rotate right through carry |
F007 | 47 | | MOV B,A | Store A into B |
F008 | 23 | LOOP | INX H | point to next location |
F009 | CD, 11, F0 | | CALL PADD | call Pair Add subroutine |
F00C | 05 | | DCR B | Decrease B by 1 |
F00D | C2, 08, F0 | | JNZ LOOP | jump to loop |
F010 | 76 | | HLT | Terminate the program |
F011 | 0E, 00 | PADD | MVI C,00H | clear C flag |
F013 | 7E | | MOV A,M | load first number from memory to A |
F014 | 23 | | INX H | point to next location |
F015 | 96 | | SUB M | sub A and memory element |
F016 | D2, 1A, F0 | | JNC STORE | if carry is not set, jump to STORE |
F019 | 0C | | INR C | else increase C by 1 |
F01A | 71 | STORE | MOV M,C | store C into memory |
F01B | 2B | | DCX H | point to previous location |
F01C | 77 | | MOV M,A | store A into memory |
F01D | 23 | | INX H | point to next location |
F01E | C9 | | RET | return from subroutine |
Output
Address | Data |
---|---|
… | … |
8001 | 16 |
8002 | 00 |
8003 | 4C |
8004 | 00 |
8005 | 0B |
8006 | 00 |
8007 | 37 |
8008 | 00 |
8009 | 74 |
800A | 00 |
… | … |
- Related Questions & Answers
- 8085 program to add two consecutive bytes of an array
- 8085 program to subtract two BCD numbers
- 8085 Program to find the HCF of two given bytes
- 8085 Program to Subtract two 8 Bit numbers
- 8085 Program to Subtract two multi-Byte numbers
- Program to find the HCF of two given bytes in 8085 Microprocessor
- 8085 Program to Exchange 10 bytes
- Program to Subtract two 8 Bit numbers in 8085 Microprocessor
- C# program to count number of bytes in an array
- 8085 program to exchange a block of bytes in memory
- 8085 program to subtract two 8-bit numbers with or without borrow
- Java program to subtract two matrices.
- C# Program to Subtract Two TimeSpan
- Subtract content of two ports by interfacing 8255 with 8085 microprocessor
- 8085 program to add numbers in an array