# 8051 Assembly code to find LCM of two numbers

Hello guys! After lot of optimization and debugging finally found a ALP program to find LCM of two numbers using 8051 micro-controller. Happy share this piece of code with you guys.

Its easy and short. We have been learning to find LCM from our school days. Finding Least common multiple of of two numbers is easy by finding GCD of those two numbers and then dividing of product of those two number by GCD. But in terms of programming its complicated! So, here I have new algorithm to find LCM of two numbers.
ALGORITHM:

1. Start
2. Store first number(num1) in a register
3. Store second number(num2) in another register
4. Initialize a counter register(Rd) to 01h
5. Compare both the values num1 and num2
• If num1 = num2 : Store num1 or num2 as result and jump to step 8
• If num1 < num2 : Swap the register values so that num1 > num2
6. Multiply num2 and Rd and divide the product with num1
7. Check the reminder
• If reminder is zero then store product obtained from multiplication in step 6 as result and jump to step 8
• Else increment Rd and repeat steps 6 and 7
8. Stop

Here is example code to find LCM of 3 and 6

CODE: