1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem in a recursive function. What's wrong with it!? MASM Assembly

Discussion in 'Assembly Language Programming (ALP) Forum' started by SamyCode, May 11, 2011.

  1. SamyCode

    SamyCode New Member

    May 11, 2011
    Likes Received:
    Trophy Points:
    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:

    int gcd (int x, int y)
    if (x % y == 0)
    return y;
    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:

    Include Irvine32.inc
    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 ?
    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
    mov eax, num2
    mov num1, eax
    mov num2, edx
    call maxDiv
    call WaitMsg
    maxDiv ENDP
    main ENDP
    END main

Share This Page