-
Notifications
You must be signed in to change notification settings - Fork 0
/
A001043M.ASM
137 lines (107 loc) · 2.75 KB
/
A001043M.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;--------------------------------------------------------------------
;
; a001043m.asm
;
; The sums of successive prime numbers
;
; OEIS A001043
;
;--------------------------------------------------------------------
.model small
.stack 100h
EXTRN dispspace:PROC
EXTRN disp0x:PROC
EXTRN dispCR:PROC
EXTRN disph16:PROC
EXTRN dispd16:PROC
.data
sieve db 1000h DUP (01h)
max dw 0FFFh
maxst dw 0040h
arr dw 547d DUP (00h)
sums dw 546d DUP (00h)
.code
a001043 PROC
push bp
mov bp, sp
push si
mov dx,@data
mov ds,dx
mov sieve[0],00h ; 0 is not a prime
mov sieve[1],00h ; 1 is not a prime
mov bx,0002h ; bx will hold the step
mov di,bx ; di is the counter thru the sieve
loop1:
add di,bx
cmp di,max
jg loop2
mov sieve[di],00h
jmp loop1
loop2:
inc bx
cmp bx,maxst ; we only have to go up to
; the sqrt of the max sieve size
jg donsie
mov di,bx
mov al,sieve[di]
cmp al,00h
je loop2
jmp loop1
donsie:
; now that the sieve is complete, move the primes into the array
mov di,0000h
mov si,0000h
mov cx,0000h
getnext:
inc di
cmp di,max
jg getsums
mov al,sieve[di]
cmp al,00h
je getnext
mov ax,di
mov arr[si], ax
add si, 02h
inc cx
jmp getnext
getsums:
mov bx, cx
dec bx
mov cx, 0000h
mov si, 0000h
getsum:
mov ax, arr[si]
inc si
inc si
add ax, arr[si]
call dispA
inc cx
cmp cx, bx
je alldone
jmp getsum
alldone:
mov ax, 4C00h
int 21h
a001043 endp
dispA PROC ; display routine for OEIS
; a......(n) in ax, n in cx
push ax
push bx
push cx
push dx
mov dx, ax
mov ax, cx
call dispd16
call dispspace
call dispspace
call dispspace
mov ax, dx
call dispd16
call dispCR
pop dx
pop cx
pop bx
pop ax
ret
dispA endp
end