-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA000040M.ASM
110 lines (85 loc) · 2.29 KB
/
A000040M.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
;--------------------------------------------------------------------
;
; a000040m.asm
;
; The prime numbers (using a sieve of Eratosthenes
;
; OEIS A000040
;
;--------------------------------------------------------------------
.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)
.code
a000040 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
dsply:
mov di,0000h
mov si,0000h
getnext:
inc di
cmp di,max
jg alldone
mov al,sieve[di]
cmp al,00h
je getnext
mov ax,di
mov arr[si], ax
call dispA000040 ; with the prime in ax, call the
; display routine
add si, 02h
jmp getnext
alldone:
mov ax, 4C00h
int 21h
a000040 endp
dispA000040 PROC ; display routine for a000040
; a000040(n) in ax
push ax
push bx
push cx
push dx
call dispd16
call dispCR
pop dx
pop cx
pop bx
pop ax
ret
dispA000040 endp
end