-
Notifications
You must be signed in to change notification settings - Fork 0
/
TOTIENT.ASM
57 lines (42 loc) · 981 Bytes
/
TOTIENT.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
;--------------------------------------------------------------------
;
; totient.asm
;
; calculate Euler's totient function for an integer n
;
; n is passed in ax - phi(n) is returned in ax
;
;--------------------------------------------------------------------
.model small
.code
EXTRN gcf:PROC
PUBLIC totient
totient PROC
push bp
mov bp, sp
push si
push bx
push cx
push dx
mov cx, ax ; cx will hold n and will count down
mov bx, ax ; bx will hold n and will preserve it
mov dx, 0000h ; dx will hold numbe of co-primes found
DoNextcp:
mov ax, cx
call gcf
cmp ax, 01h
jne NotCoPrime
inc dx
NotCoPrime:
dec cx
cmp cx, 0000h
jg DoNextcp
mov ax, dx
pop dx
pop cx
pop bx
pop si
pop bp
ret
totient endp
end