-
Notifications
You must be signed in to change notification settings - Fork 0
/
GCF.ASM
76 lines (55 loc) · 1.22 KB
/
GCF.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;--------------------------------------------------------------------
;
; gcf.asm
;
; find the greatest common factor of two numbers using Euclid's method
;
; n1 passed in ax, n2 passed in bx, gcf returned in ax
;
;--------------------------------------------------------------------
.model small
.data
arr dw 0014h dup (00h)
n1 dw 0000h
n2 dw 0000h
n dw 0000h
.code
PUBLIC gcf
gcf PROC
push bp
mov bp, sp
push si
push ds
push bx
push cx
push dx
mov n1, ax ; store n1, n2
mov n2, bx
mov bx, n1 ; put higher number in n1
mov cx, n2
cmp bx, cx
jge TakeStep
mov n1, cx
mov n2, bx
TakeStep:
mov dx, 0000h ; implement Euclid's method
mov ax, n1
mov bx, n2
div bx
cmp dx, 0000h
je Found
mov n1, bx
mov n2, dx
jmp TakeStep
Found:
mov ax, bx
AllDone:
pop dx
pop cx
pop bx
pop ds
pop si
pop bp
ret
gcf endp
end