HotCode
Programmer
- Sep 29, 2011
- 4
Ok well I am working on a program that does the GCD thing but needs to be recursive. My problem is I dont know how to call it with the values that I have in the data section and two I dont know if it works right or not.
well here is what I have so far
Thanks for any help
well here is what I have so far
Thanks for any help
Code:
TITLE MASM GCD (GCD.asm)
INCLUDE Irvine32.inc
.data
myMessage BYTE "GCD Recursive",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
call Crlf
call GCD
call WriteInt
exit
main ENDP
;------------------------------------------------
GCD PROC,
denom:DWORD,
divisor:DWORD
; This finds GCD
; Gets values from stored values
;returns NA
;------------------------------------------------
mov ebx,divisor ;this is the divider make sure its smaller number!
mov edx,denom ;this is value 1
div ebx ;divide int1 by int2
cmp edx,0 ;does remainder = 0 ?
je L1 ;yes: quit
call GCD ;no: call GCD agian
L1:
mov eax,ebx ;EAX = GCD
pop edx
pop ebx
ret
GCD ENDP
END main