-
Notifications
You must be signed in to change notification settings - Fork 0
/
A000005M.ASM
112 lines (83 loc) · 2 KB
/
A000005M.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
;
; a000005m.asm
;
; count the divisors of numbers up to 1000
;
; OEIS A000005
;
.model small
.stack 100h
EXTRN dispspace:PROC
EXTRN disp0x:PROC
EXTRN dispCR:PROC
EXTRN disph16:PROC
EXTRN dispd16:PROC
.data
divisor dw 0001h
max dw 1000h
.code
a000005 proc
mov dx, @data
mov ds, dx
mov si, 0000h
mov bx,0001h ; bx will hold the number whose divisors
; we are trying to count
CountDiv:
mov cx,0000h ; cx = number of divisors found
mov dx,0000h ; dx will hold remainder after division
mov divisor,01h
DoNext:
mov ax,bx
mov dx,0000h
div divisor
or dx,dx ; does the remainder = 0?
jnz DontCount ; if not, don't count it because divisor
; does not divide ax
inc cx
DontCount:
inc divisor
cmp divisor, bx
jle DoNext
call dispA000005
inc bx
cmp bx, max
jle CountDiv
AllDone:
mov ax, 4C00H ; exit to dos
int 21h
ret
a000005 endp
dispA000005 PROC ; display routine for a000005
; n in bx, num divisors in cx
push ax
push bx
push cx
push dx
mov ax, bx
call disph16
call dispspace
call dispspace
call dispspace
call dispspace
mov ax, bx
call dispd16
call dispspace
call dispspace
call dispspace
call dispspace
mov ax, cx
call disph16
call dispspace
call dispspace
call dispspace
call dispspace
mov ax, cx
call dispd16
call dispCR
pop dx
pop cx
pop bx
pop ax
ret
dispA000005 endp
end