Greatest Common Divisor (GCD) The greatest common divisor (GCD) of two integers
ID: 3939136 • Letter: G
Question
Greatest Common Divisor (GCD) 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, described 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. CAN YOU PLEASE INCLUDE SCREENSHOT OR PICS OR PROGRAM RUNNING Greatest Common Divisor (GCD) 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, described 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. CAN YOU PLEASE INCLUDE SCREENSHOT OR PICS OR PROGRAM RUNNING Greatest Common Divisor (GCD) 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, described 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. CAN YOU PLEASE INCLUDE SCREENSHOT OR PICS OR PROGRAM RUNNING
Explanation / Answer
DATA SEGMENT
NUM1 DW 000AH
NUM2 DW 0004H
GCD DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM1
MOV BX,NUM2
UP: CMP AX,BX
JE EXIT
JB EXCG
UP1: MOV DX,0H
DIV BX
CMP DX,0
JE EXIT
MOV AX,DX
JMP UP
EXCG:XCHG AX,BX
JMP UP1
EXIT:MOV GCD,BX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.