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

A little Help with what I am doing wrong here

Discussion in 'Assembly Language Programming (ALP) Forum' started by LordGus, Oct 25, 2011.

  1. LordGus

    LordGus New Member

    Oct 25, 2011
    Likes Received:
    Trophy Points:
    Hello, I have got program running and its doing ok, but it keeps giving the wrong answer and I dont know where\what I did wrong. It looks all right to me but I know I am missing something simple I just cant put my finger on it to save my life.
    What it should do is find the GCD of two numbers and print that off. Am I not pushing the val1 and val2 right for the GCD function? should I use offset of val1 and val2? Or si there a better way?
    Thanks for any help

    TITLE MASM GCD                      (GCD.asm)
    ; Description:GCD recursive
    ; Revision date:
    INCLUDE Irvine32.inc
    myMessage BYTE "GCD Recursive",0dh,0ah,0
    myMess2   BYTE "The GCD is = " ,0dh,0ah,0
    ;first set of nums
    val1 DWORD  5
    val2 DWORD  20
    main PROC
        call Clrscr  
        mov     edx,offset myMessage
        call WriteString        ;write message
        call Crlf                ;new line
        push val1
        push val2
        call GCD
    main ENDP
    ; This finds GCD
    ; Gets values from stored values
    ;returns NA
            xor edx,edx
            mov eax,dword ptr[esp+8] ;dividend
            mov ebx,dword ptr[esp+4] ;divisor
            div ebx              ;eax/ebx
            cmp  edx,0           ;remainder in edx
            je   L1                 ;yes: quit
            call GCD             ;no: call GCD agian
            mov eax,ebx             ;move the divisor into eax for printing i.e GCD    
            mov     edx,offset myMess2
            call WriteString
            call WriteInt        ;Display GCD WriteInt uses EAX = qutent
            call crlf
            ret 8                ;clean up the stack
    END main

Share This Page