ASSEMBLY LANGUAGE!!!!! For this program you will find the largest common factor
ID: 3717378 • Letter: A
Question
ASSEMBLY LANGUAGE!!!!!
For this program you will find the largest common factor for 2 numbers, a and b.
The largest common factor is the largest positive number that divides the two numbers.
The C++ code for doing this is:
int LCF (int a, int b)
{
if (a == 0 && b == 0)
b = 1;
else
if (b == 0)
b = a;
else
if (a != 0)
while (a != b)
if (a < b)
b -= a;
else
a -= b;
return b;
}
In your code, you should follow this C++ code as closely as possible.
Put a in eax, and b in ebx.
Do not use any loop instructions directly.
Do use compare and jump instructions.
Do not use any procedures except MyProgram.
You code should be your work alone.
You example of your console window should look as follows:
Please provide an integer for b: 8
Please provide an integer for a: 4
The largest common factor of a and b is: +4
Explanation / Answer
data segment
n1 db "Enter first number : $"
n2 db "Enter sec number : $"
hcf Db ?
data ends
code segment
assume DS:data CS:code
st:
mov ax,data
mov DS,ax
mov ax,n1
mov bx,n2
while:mov dx,0
mov cx,bx
div bx
mov bx,dx
mov ax,cx
cmp bx,0
jne while
mov hcf,ax
ret hcf
mov AH,4CH
int 21H
code ends
END st
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.