I'm trying to do a recursive function in Assembly in order to get the Max common divisor between two numbers. In C++ this would be easy, as I created a function before that is working, like this one:
Code:
int gcd (int x, int y)
{
if (x % y == 0)
return y;
else
return gcd (y, x % y);
}
Code:
Include Irvine32.inc .data show BYTE "This program will show you the max. comun divisor between the 2 numbers of your choose ", 0 show1 BYTE "Enter the first number: ", 0 show2 BYTE "Enter the second number: ", 0 show3 BYTE "Enter the third and final number: ", 0 num1 SDWORD ? num2 SDWORD ? num3 SDWORD ? .code main PROC mov edx, OFFSET show call WriteString call Crlf mov edx, OFFSET show1 call WriteString call ReadInt mov num1, eax call Crlf mov edx, OFFSET show2 call WriteString call ReadInt mov num2, eax call Crlf mov eax, 0 call maxDiv maxDiv PROC show4 BYTE "The greatest common divisor from this two number is: ", 0 mov eax, num1 div num2 .IF edx == 0 mov edx, OFFSET show4 call WriteString mov eax, num1 call WriteInt .ElSE mov eax, num2 mov num1, eax mov num2, edx call maxDiv .ENDIF call WaitMsg maxDiv ENDP main ENDP END main
