-
Notifications
You must be signed in to change notification settings - Fork 0
/
A000067M.ASM
162 lines (125 loc) · 3.54 KB
/
A000067M.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
;--------------------------------------------------------------------
;
; a000067m.asm
;
; Number of positive integers <= 2^n of the form x^2 + 2y^2
;
; OEIS A000067
;
;--------------------------------------------------------------------
.model small
.stack 100h
EXTRN dispspace:PROC
EXTRN disp0x:PROC
EXTRN dispCR:PROC
EXTRN disph16:PROC
EXTRN dispd16:PROC
.data
x dw 00h
y dw 00h
arr dw 10h DUP (00h)
used dw 5000h DUP (00h)
.code
a000067 PROC
push bp
mov bp, sp
push si
mov dx,@data
mov ds,dx
xloop:
yloop:
mov ax, y
mul y
cmp ax, 05000h
jg doney
cmp ax, 05000h
jg doney
mov dx, 02h
mul dx
mov bx, ax ; bx = 2y^2, which is less than 4000h
mov ax, x
mul x ; ax = x^2
cmp ax, 05000h
jg donex
add ax, bx ; ax = x^2 + 2y^2
cmp ax, 05000h
jg doney
; check to be sure that the integer in ax hasn't already been counted
push ax
push dx
mov bx, 02h
mul bx
mov bx, ax
pop dx
pop ax
cmp used[bx], 00h
jg donecount ; if it has been counted, don't
; count it again
mov used[bx], 01h ; mark it so it won't be counted
; again
mov cx, 0000h
mov dx, 0001h
mov si, 0000h
isless: ; now see which buckets the integer
; falls into for counting
cmp ax, 00h ; don't count it if it's zero
je dontcount
cmp ax, dx ; check 2^n
jg dontcount
inc arr[si] ; count if it's <=
dontcount:
inc cx ; cx = n
cmp cx, 0Eh ; if we have exceed 0E, we're done
jg donecount
inc si
inc si
shl dx, 1 ; dx = 2^n
jmp isless
donecount:
inc y
jmp yloop
doney:
inc x
cmp x, 80h
jg donex
mov y, 0
jmp xloop
donex:
mov cx, 0000h
mov si, 0000h
disploop:
mov ax, arr[si]
call dispA
inc cx
cmp cx, 0Eh
jg alldone
inc si
inc si
jmp disploop
alldone:
mov ax, 4C00h
int 21h
a000067 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