1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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

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

Share This Page