Mixed Language ( C and TASM) program to find the LCM of two numbers

On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.
Objective:
Write a mixed language code to calculate LCM of  2 numbers.
Prerequisite:
Turbo C++ Compiler
Algorithm:
1.      Start
2.      Declare 3 numbers a, b, lcm as integers.
3.      Move the a and b value to AX and BX respectively
4.      Repeat step no 5 till AX/BX division not gives the remainder = 0
5.      Add AXßAX+BX
6.      As remainder 0 gets obtained AX value is LCM value. Move AX value to lcm
7.      Display the lcm value.

8.      Stop.
TASM Program :
include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int a,b,temp;
cout<<"Please enter first number:"<<endl;
cin>>a;
cout<<"Please enter second number:"<<endl;
cin>>b;
cout<<endl;
temp = a;
asm mov ax,a
asm mov bx,b
bck:
asm cmp ax,0000h
asm jz ex
asm cmp bx,0000h
asm jz ex
asm div bl
asm cmp ah,00h
asm jz ex
temp = temp + a;
asm mov ax,temp
asm mov bx,b
asm jmp bck
ex:
cout<<"The LCM is: "<<temp;
getch();
}
output:-
Please enter first number:
10                                                                              
Please enter second number:                                                     
37                                                                              

The LCM is: 370 
--------------------------------

0 comments: