Problem in a recursive function. What's wrong with it!? MASM Assembly
Hi people. I'm new here. I hope that someone can help me because I have to send this homeword in less than 24 hours.
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);
}
Fine, but I'm trying to do the same in a Assembly Procedure called "maxDiv". I will paste my entire code to see if you guys please can help me. The program runs without errors and it starts fine but when it enters to the function, the program freeze and VS tells me "project.exe has triggered a breakpoint". My code is as follow:
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
|