The greatest common divisor (GCD) of two integers is the largest integer that wi
ID: 3645545 • Letter: T
Question
The greatest common divisor (GCD) of two integers is the largest integer that will evenly divide both integers. The GCD algorithm involves integer division in a loop, describe by the following C++ code:int GCD (int x, int y)
{
x = abs (x); // absolute value
y = abs (y);
do {
int n = x % y;
x = y;
y = n;
} while (y > 0);
return x;
Implement this function in assembly language and write a test program that calls the function several times, passing it different values. Display all results on the screen.
Explanation / Answer
MOV AX,4000H MOV DS,AX MOV SI,0000H MOV AL,20 MOV CL,22 MOV AH,00H CMP AL,CL JA NEXT XCHG AL,CL NEXT: MOV BL,CL DIV CL CMP AH,00H JE DOWN MOV AL,CL MOV CL,AH MOV AH,00H JMP NEXT DOWN: MOV BH,BL ;RESULT IS THE ;WHERE GCD IS TO BE STORED HLT
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.