NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


CODES EXPLORER

Learn Embedded C, ML, Python, C++, 8051, ARM



8051
8051 Assembly Code To Find LCM Of Two Numbers
July 28, 2017 codesexplorer0 Comments

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:

Start
Store first number(num1) in a register
Store second number(num2) in another register
Initialize a counter register(Rd) to 01h
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
Multiply num2 and Rd and divide the product with num1
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
Stop
Here is example code to find LCM of 3 and 6

CODE:


<br />ORG 0000h<br /> LJMP main<br /> ORG 0040h<br /> main: MOV R0,#03h ; Initializing first number<br /> MOV R1,#06h ; Initializing second number<br /> MOV R2,#01h ; Initializing counter register(Rd)<br /> MOV A,R0<br /> MOV B,R1<br /> CJNE A,B,lab
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.