Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   A little Help with what I am doing wrong here (http://www.go4expert.com/forums/little-help-i-doing-wrong-t27016/)

LordGus 25Oct2011 19:34

A little Help with what I am doing wrong here
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

All times are GMT +5.5. The time now is 07:15.