- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 compute LCM in 8085 Microprocessor
Now let us see a program of Intel 8085 Microprocessor. This program will find the LCM of two 8-bit numbers.
Problem Statement −
Write 8085 Assembly language program to find LCM of two 8-bit numbers stored at location 8000H and 8001H
Discussion −
In this program we are reading the data from 8000H and 8001H. By loading the number, we are storing it at C register, and clear the B register. The second number is loaded into Accumulator. Set DE as the 2’s complement of BC register. This DE is used to subtract BC from HL pair.
The method is like this: let us say the numbers are 25 and 15. When we divide the first number by second, and then if there is no remainder, then the first number is the LCM. But for this case the remainder is present. Then we will check the next multiple of 25 to check the divisibility. When the remainder becomes 0, the program terminates and the result is stored.
Input
First input
Address | Data |
---|---|
. . . | . . . |
8000 | 03 |
8001 | 07 |
. . . | . . . |
Second input
Address | Data |
---|---|
. . . | . . . |
8000 | 23 |
8001 | 07 |
. . . | . . . |
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 21, 00, 80 | | LXI H, 8000H | Point 8000H to get first number |
F003 | 4E | | MOV C,M | Load memory element to C |
F004 | 06, 00 | | MVI B, 00H | Clear B register |
F006 | 23 | | INX H | Point to next location |
F007 | 7E | | MOV A,M | Load second number to Acc |
F008 | 2F | | CMA | Complement Acc |
F009 | 5F | | MOV E,A | Load 1's complemented form of A to E |
F00A | 16, FF | | MVI D, FFH | Load 1's complemented form of 00H |
F00C | 13 | | INX D | Increase DE register pair |
F00D | 21, 00, 00 | | LXI H, 0000H | Load 0000H into HL pair |
F010 | 09 | NEXT | DAD B | Add BC with HL |
F011 | 22, 50, 80 | | SHLD 8050H | Store HL content into 8050H |
F014 | 19 | LOOP | DAD D | Add DE with HL |
F015 | D2, 20, F0 | | JNC SKIP | When CY = 0, jump to SKIP |
F018 | 7C | | MOV A,H | Get H content to A |
F019 | B5 | | ORA L | OR L with A |
F01A | CA, 26, F0 | | JZ EXIT | When HL is 0000, jump to EXIT |
F01D | C3, 14, F0 | | JMP LOOP | Jump to Loop |
F020 | 21, 50, 80 | SKIP | LHLD 8050H | Load HL from 8050H |
F023 | C3, 10, F0 | | JMP NEXT | Jump to NEXT |
F026 | 2A, 50, 80 | EXIT | LHLD 8050H | Store HL pair as LCM |
F029 | 76 | | HLT | Terminate the program |
Output
first output
Address | Data |
---|---|
. . . | . . . |
8050 | 15 |
8051 | 00 |
. . . | . . . |
second output
Address | Data |
---|---|
. . . | . . . |
8050 | 3B |
8051 | 01 |
. . . | . . . |