

- 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
Program to find the HCF of two given bytes in 8085 Microprocessor
Here we will see how to find the HCF or GCD of two given bytes using 8085. The numbers are 8-bit numbers, nor larger than that.
Problem Statement−
Write an 8085 Assembly language program to find the HCF or GCD of two numbers stored at memory location 8000H and 8001H.
Discussion−
Here we will use the Euclidean algorithm to find HCF. This algorithm is very simple. We have to follow these steps−
- If first number and second number are same, then
a) go to step 3.
Else if first number < second number, the
b) exchange no1 and no2.
- first-number ← first-number – second-number; go to step 1
- Display result as first-number
The values are stored at location 8000H and 8001H, and the result will be stored at location 8050H.
Input
First Input
Address | Data |
---|---|
… | … |
8000 | 2D |
8001 | 69 |
… | … |
8050 | 0F |
… | … |
Second Input
Address | Data |
---|---|
… | … |
8000 | 25 |
8001 | 35 |
… | … |
8050 | 01 |
… | … |
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments | |
---|---|---|---|---|---|
F000 | 21, 00, 80 | | LXI H,8000H | Point to the first number | |
F003 | 7E | | MOV A,M | Load the first number into Acc | |
F004 | 23 | | INX H | Point to next location | |
F005 | 46 | | MOV B,M | Load the second number | |
F006 | B8 | LOOP | CMP B | Compare B with A | |
F007 | CA, 17, F0 | | JZ STORE | When A and B are same, store the result | |
F00A | DA, 11, F0 | | JC EXG | If B > A, then exchange B and A | |
F00D | 90 | | SUB B | if B < A, subtract B from A | |
F00E | C3, 06, F0 | | JMP LOOP | Jump to LOOP | |
F011 | 48 | EXG | MOV C,B | Load C with B | |
F012 | 47 | | MOV B,A | Move A to B | |
F013 | 79 | | MOV A,C | Move C to A | |
F014 | C3, 06, F0 | | JMP LOOP | Jump to LOOP | |
F017 | 32, 50, 80 | STORE | STA 8050H | Store the value into memory | |
F01A | 76 | | HLT | Terminate the program | |
| | | | | |
Output
First Output
Address | Data |
---|---|
… | … |
8050 | 0F |
… | … |
Second Output
Address | Data |
---|---|
… | … |
8050 | 01 |
… | … |
- Related Questions & Answers
- 8085 Program to find the HCF of two given bytes
- 8085 program to add two consecutive bytes of an array
- 8085 program to subtract two consecutive bytes of an array
- Java program to find the GCD or HCF of two numbers
- Program to find GCD or HCF of two numbers in C++
- 8085 Program to Exchange 10 bytes
- Program to Add two multi-byte numbers in 8085 Microprocessor
- Program to Add two 8 Bit numbers in 8085 Microprocessor
- Program to Subtract two 8 Bit numbers in 8085 Microprocessor
- Program to Divide two 8 Bit numbers in 8085 Microprocessor
- Program to check for two out of five code in 8085 Microprocessor
- 8085 program to exchange a block of bytes in memory
- Program to convert two-digit hex to two ASCII values in 8085 Microprocessor
- Program to Find the largest number in an array of data in 8085 Microprocessor
- Program to Find the smallest number in an array of data in 8085 Microprocessor
Advertisements