8085 Program to compute LCM


Now let us see a program of Intel 8085 Microprocessor. This program will find the LCM of two8-bit numbers.

Problem Statement

Write 8085 Assembly language program to find LCM of two 8-bit numbers stored at location8000H 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 BCregister. 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

AddressData
.
.
.
.
.
.
800003
800107
.
.
.
.
.
.

second input

AddressData
.
.
.
.
.
.
800023
800107
.
.
.
.
.
.

Flow Diagram

Program

AddressHEX CodesLabelsMnemonicsComments
F00021, 00, 80
LXI H, 8000H   Point 8000Hto get first number
F0034E
MOV C, MLoad memory element to C
F00406, 00
MVI B, 00H  Clear B register
F00623
INX H   Point to next location
F0077E
MOV A, MLoad second number to Acc
F0082F
CMAComplementAcc
F0095F
MOV E, ALoad 1's complemented form of A to E
F00A16, FF
MVI D, FFH  Load 1's complemented form of 00H
F00C13
INX D   Increase DEregister pair
F00D21, 00, 00
LXI H, 0000H   Load 0000Hinto HL pair
F01009NEXTDAD B   Add BC with HL
F01122, 50, 80
SHLD 8050H  Store HL content into 8050H
F01419LOOPDAD D   Add DE withHL
F015D2, 20, F0
JNC SKIP    When CY = 0,jump to SKIP
F0187C
MOV A, HGet H content to A
F019B5
ORA L   OR L with A
F01ACA, 26, F0
JZ EXITWhen HL is0000, jump to EXIT
F01DC3, 14, F0
JMP LOOP    Jump to Loop
F02021, 50, 80SKIPLHLD 8050H  Load HL from8050H
F023C3, 10, F0
JMP NEXT    Jump to NEXT
F0262A, 50, 80EXITLHLD 8050H  Store HL pair as LCM
F02976
HLTTerminate the program


Output

first output

AddressData
.
.
.
.
.
.
805015
805100
.
.
.
.
.
.

second output

AddressData
.
.
.
.
.
.
80503B
805101
.
.
.
.
.
.

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements