8086 汇编语言程序求两个数的 GCD

8086 Assembly Language Program to find GCD of two numbers

当它点击“Ret 8”时,我的程序停止工作。谁能告诉我为什么?

求用户输入的2个数字的GCD。一直循环直到你停止它。

提前致谢

INCLUDE irvine32.inc

.data

    msg1 byte " Enter first number", 0ah, 0dh,0
    msg2 byte " Enter second number",0ah, 0dh,0
    msg3 byte " GCD is ",0ah,0dh,0
    ValA DWORD ?
    ValB DWORD ?

.code

main PROC

     start:
            mov edx, offset msg1
            call WriteString
            call ReadDec
            mov ValA,eax



            mov edx, offset msg2
            call WriteString
            call ReadDec
            mov ValB,eax

            mov eax,DWORD ptr[ValA]
            mov ebx,DWORD ptr[ValB]
            push ValB
            push ValA
            call CalcGcd
            call DumpRegs
            call start

    exit
    main ENDP


CalcGcd PROC

        push ebp
        mov ebp, esp
        xor edx,edx
        mov eax, [ebp+8]
        mov ebx, [ebp+12]

    L1:
        cmp eax,ebx
        JE DONE
        JB EXCH

    L2:
        div ebx
        cmp edx,0
        JE DONE
        mov eax,ebx
        mov ebx,edx
        JMP L1

    EXCH:
        XCHG eax,ebx
        JMP L1

    DONE:
        mov eax,ebx
        mov edx, offset msg3
        call writestring
        call writedec
        ret 8



    CalcGcd ENDP
    END main

代码在 return 之前缺少 pop ebpcall start 将不断循环,直到程序用完堆栈 space。