感谢大家的帮助,我做了一些非常好的改变,但现在它给了我一个 +4198498 的答案,而不是 5,我知道第一组值是错误的。我推错了什么或没有正确弹出注册表?我使用 ret 8 清理了堆栈,它应该为下一次调用清理堆栈,对吗?
这是我到目前为止所拥有的:
TITLE MASM GCD (GCD.asm)
; Description:GCD recursive
;
; Revision date:
INCLUDE Irvine32.inc
.data
myMessage BYTE "Assignment 7 GCD Recursive style",0dh,0ah,0
myMess2 BYTE "GCD = " ,0dh,0ah,0
;first set of nums
val1 DWORD 5
val2 DWORD 20
;second set of nums
val3 DWORD 24
val4 DWORD 18
;3rd set
val5 DWORD 11
val6 DWORD 7
;4th set
val7 DWORD 432
val8 DWORD 226
;5th set
val9 DWORD 26
val10 DWORD 13
.code
main PROC
call Clrscr
mov edx,offset myMessage
call WriteString ;write message
call Crlf ;new line
push val1
push val2
call GCD
exit
main ENDP
;------------------------------------------------
GCD PROC,
; 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
L1:
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
GCD ENDP
END main