-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutinesf.asm
492 lines (474 loc) · 10.5 KB
/
routinesf.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
extern xdelta,ydelta,pixel,xres,yres,xgap,ygap,aedge,bedge,ac,bc,az,bz,sizev
extern count,converge,limit,temp,tempb,one,two,ncols,im,imaged,Colors,popped
extern resadd,resadd1,resadd2,m,n,fractaltype,a,b,xres1,yres1,xres2,yres2
extern aedge1,bedge1,xdelta1,ydelta1
extern aedge2,bedge2,xdelta2,ydelta2
extern aedge3,bedge3,xdelta3,ydelta3
extern aedge4,bedge4,xdelta4,ydelta4
extern aedge5,bedge5,xdelta5,ydelta5
extern a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,a6,b6,a7,b7,a8,b8
extern numpixels,numpixels1,numpixels2
extern cydir,cyinc,off
extern Mandelbrot
extern Julia
%define MANDELBROT 0
%define JULIA 1
global _Mandelbrot
_Mandelbrot:
mov dword [pixel],0
fld dword [xdelta]
fdiv dword [xres]
fstp dword [xgap] ; xgap=xdelta/xres
fld dword [ydelta]
fdiv dword [yres]
fstp dword [ygap] ; ygap=ydelta/yres
fldz
Loopm: fst dword [m] ; for (m=0;m<yres;m++)
fmul dword [ygap]
fadd dword [bedge]
fstp dword [bc] ; bc=m*ygap+bedge
fldz
Loopn: fst dword [n] ; for (n=0;n<xres;n++)
fmul dword [xgap]
fadd dword [aedge]
fstp dword [ac] ; ac=n*xgap+aedge
fldz
fst dword [az] ; az=0
fst dword [bz] ; bz=0
fstp dword [sizev] ; sizev=0 (size must be reserved word)
mov dword [count],0 ; count=0
Loopw: fld dword [sizev]
fcomp dword [converge]
fnstsw ax
test ah,65
je Exitw
mov eax,[limit]
cmp [count],eax ; was cmp count,limit when limit was #define
jg Exitw ; while (size<=converge && count<=limit)
fld dword [az]
fst dword [temp] ; temp=az
fmul dword [az]
fadd dword [ac]
fstp dword [az]
fld dword [bz]
fmul dword [bz]
fstp dword [tempb]
fld dword [az]
fsub dword [tempb]
fstp dword [az] ; az=az*az-bz*bz+ac
fld dword [bz]
fmul dword [temp]
fmul dword [two]
fadd dword [bc]
fstp dword [bz] ; bz=temp*bz*2+bc
add dword [count],1 ; count++
fld dword [az]
fmul dword [az]
fstp dword [tempb]
fld dword [bz]
fmul dword [bz]
fadd dword [tempb]
fstp dword [sizev] ; size=(az*az+bz*bz)
jmp Loopw ; end while
Exitw: mov eax,[limit]
cmp [count],eax
jle ok
mov dword [count],0 ; if (count>limit) count=0
jmp ok2
ok: mov eax,[off]
add [count],eax
mov eax,[count] ;
mov edx,0 ;
idiv dword [ncols] ; MODI 255
mov [count],edx ;
add dword [count],1 ; else count=(count+off)%255+1
ok2: mov eax,[count]
mov ebx,[pixel]
mov [imaged+ebx],eax ; save count for color cycling (not aligned)
imul eax,3
add eax,2
mov cl,[Colors+eax]
sub eax,1
mov ebx,[pixel]
mov [im+ebx],cl
add dword [pixel],1
mov cl,[Colors+eax]
sub eax,1
mov ebx,[pixel]
mov [im+ebx],cl
add dword [pixel],1
mov cl,[Colors+eax]
mov ebx,[pixel]
mov [im+ebx],cl
add dword [pixel],1
add dword [pixel],1 ; 32-bit image buffer instead of 24
fld dword [n]
fadd dword [one]
fst dword [n]
fcom dword [xres]
fnstsw ax
test ah,1
jne Loopn ; end Loop n
mov eax,[resadd]
add [pixel],eax
fstp dword [popped]
fld dword [m]
fadd dword [one]
fst dword [m]
fcom dword [yres]
fnstsw ax
test ah,1
jne Loopm ; end Loop m
fstp dword [popped]
;call Cycle
ret
global _Julia
_Julia: mov dword [pixel],0
fld dword [xdelta]
fdiv dword [xres]
fstp dword [xgap] ; xgap=xdelta/xres
fld dword [ydelta]
fdiv dword [yres]
fstp dword [ygap] ; ygap=ydelta/yres
fldz
Loopmj: fst dword [m] ; for (m=0;m<yres;m++)
fmul dword [ygap]
fadd dword [bedge]
fstp dword [bc] ; bc=m*ygap+bedge
fldz
Loopnj: fst dword [n] ; for (n=0;n<xres;n++)
fmul dword [xgap]
fadd dword [aedge]
fst dword [ac] ; ac=n*xgap+aedge
fstp dword [az] ; az=ac
fld dword [bc]
fstp dword [bz] ; bz=bc
fldz
fstp dword [sizev] ; sizev=0 (size must be reserved word)
mov dword [count],0 ; count=0
Loopwj: fld dword [sizev]
fcomp dword [converge]
fnstsw ax
test ah,65
je Exitwj
mov eax,[limit]
cmp [count],eax
jg Exitwj ; while (size<=converge && count<=limit)
fld dword [az]
fst dword [temp] ; temp=az
fmul dword [az]
fadd dword [a]
fstp dword [az]
fld dword [bz]
fmul dword [bz]
fstp dword [tempb]
fld dword [az]
fsub dword [tempb]
fstp dword [az] ; az=az*az-bz*bz+a
fld dword [bz]
fmul dword [temp]
fmul dword [two]
fadd dword [b]
fstp dword [bz] ; bz=temp*bz*2+b
add dword [count],1 ; count++
fld dword [az]
fmul dword [az]
fstp dword [tempb]
fld dword [bz]
fmul dword [bz]
fadd dword [tempb]
fstp dword [sizev] ; size=(az*az+bz*bz)
jmp Loopwj ; end while
Exitwj: mov eax,[limit]
cmp [count],eax
jle okj
mov dword [count],0 ; if (count>limit) count=0
jmp ok2j
okj: mov eax,[off]
add dword [count],eax
mov eax,[count] ;
mov edx,0 ;
idiv dword [ncols] ; MODI 255
mov [count],edx ;
add dword [count],1 ; else count=(count+off)%255+1
ok2j: mov eax,[count]
mov ebx,[pixel]
mov [imaged+ebx],eax ; save count for color cycling (not aligned)
imul eax,3
add eax,2
mov cl,[Colors+eax]
sub eax,1
mov ebx,[pixel]
mov [im+ebx],cl
add dword [pixel],1
mov cl,[Colors+eax]
sub eax,1
mov ebx,[pixel]
mov [im+ebx],cl
add dword [pixel],1
mov cl,[Colors+eax]
mov ebx,[pixel]
mov [im+ebx],cl
add dword [pixel],1
add dword [pixel],1 ; 32-bit image buffer instead of 24
fld dword [n]
fadd dword [one]
fst dword [n]
fcom dword [xres]
fnstsw ax
test ah,1
jne Loopnj ; end Loop n
mov eax,[resadd]
add [pixel],eax
fstp dword [popped]
fld dword [m]
fadd dword [one]
fst dword [m]
fcom dword [yres]
fnstsw ax
test ah,1
jne Loopmj ; end Loop m
fstp dword [popped]
;call Cycle
ret
global Choice1
Choice1: fld dword [aedge1]
fstp dword [aedge]
fld dword [bedge1]
fstp dword [bedge]
fld dword [xdelta1]
fstp dword [xdelta]
fld dword [ydelta1]
fstp dword [ydelta]
mov dword [fractaltype],MANDELBROT
call Mandelbrot
ret
global Choice2
Choice2: fld dword [aedge2]
fstp dword [aedge]
fld dword [bedge2]
fstp dword [bedge]
fld dword [xdelta2]
fstp dword [xdelta]
fld dword [ydelta2]
fstp dword [ydelta]
mov dword [fractaltype],MANDELBROT
call Mandelbrot
ret
global Choice3
Choice3: fld dword [aedge3]
fstp dword [aedge]
fld dword [bedge3]
fstp dword [bedge]
fld dword [xdelta3]
fstp dword [xdelta]
fld dword [ydelta3]
fstp dword [ydelta]
mov dword [fractaltype],MANDELBROT
call Mandelbrot
ret
global Choice4
Choice4: fld dword [aedge4]
fstp dword [aedge]
fld dword [bedge4]
fstp dword [bedge]
fld dword [xdelta4]
fstp dword [xdelta]
fld dword [ydelta4]
fstp dword [ydelta]
fld dword [a1]
fstp dword [a]
fld dword [b1]
fstp dword [b]
mov dword [fractaltype],JULIA
call Julia
ret
global Choice5
Choice5: fld dword [aedge4]
fstp dword [aedge]
fld dword [bedge4]
fstp dword [bedge]
fld dword [xdelta4]
fstp dword [xdelta]
fld dword [ydelta4]
fstp dword [ydelta]
fld dword [a2]
fstp dword [a]
fld dword [b2]
fstp dword [b]
mov dword [fractaltype],JULIA
call Julia
ret
global Choice6
Choice6: fld dword [aedge4]
fstp dword [aedge]
fld dword [bedge4]
fstp dword [bedge]
fld dword [xdelta4]
fstp dword [xdelta]
fld dword [ydelta4]
fstp dword [ydelta]
fld dword [a3]
fstp dword [a]
fld dword [b3]
fstp dword [b]
mov dword [fractaltype],JULIA
call Julia
ret
global Choice7
Choice7: fld dword [aedge4]
fstp dword [aedge]
fld dword [bedge4]
fstp dword [bedge]
fld dword [xdelta4]
fstp dword [xdelta]
fld dword [ydelta4]
fstp dword [ydelta]
fld dword [a4]
fstp dword [a]
fld dword [b4]
fstp dword [b]
mov dword [fractaltype],JULIA
call Julia
ret
global Choice8
Choice8: fld dword [aedge4]
fstp dword [aedge]
fld dword [bedge4]
fstp dword [bedge]
fld dword [xdelta4]
fstp dword [xdelta]
fld dword [ydelta4]
fstp dword [ydelta]
fld dword [a5]
fstp dword [a]
fld dword [b5]
fstp dword [b]
mov dword [fractaltype],JULIA
call Julia
ret
global Choice9
Choice9: fld dword [aedge4]
fstp dword [aedge]
fld dword [bedge4]
fstp dword [bedge]
fld dword [xdelta4]
fstp dword [xdelta]
fld dword [ydelta4]
fstp dword [ydelta]
fld dword [a6]
fstp dword [a]
fld dword [b6]
fstp dword [b]
mov dword [fractaltype],JULIA
call Julia
ret
global Choice0
Choice0: fld dword [aedge4]
fstp dword [aedge]
fld dword [bedge4]
fstp dword [bedge]
fld dword [xdelta4]
fstp dword [xdelta]
fld dword [ydelta4]
fstp dword [ydelta]
fld dword [a7]
fstp dword [a]
fld dword [b7]
fstp dword [b]
mov dword [fractaltype],JULIA
call Julia
ret
global Choicea
Choicea: fld dword [aedge4]
fstp dword [aedge]
fld dword [bedge4]
fstp dword [bedge]
fld dword [xdelta4]
fstp dword [xdelta]
fld dword [ydelta4]
fstp dword [ydelta]
fld dword [a8]
fstp dword [a]
fld dword [b8]
fstp dword [b]
mov dword [fractaltype],JULIA
call Julia
ret
global Choiceb
Choiceb: fld dword [xres]
fcomp dword [xres1]
fnstsw ax
test ah,64
jne To128
fld dword [xres1]
fstp dword [xres]
fld dword [yres1]
fstp dword [yres]
mov eax,[numpixels1]
mov [numpixels],eax
mov eax,[resadd1]
mov [resadd],eax
jmp resend
To128: fld dword [xres2]
fstp dword [xres]
fld dword [yres2]
fstp dword [yres]
mov eax,[numpixels2]
mov [numpixels],eax
mov eax,[resadd2]
mov [resadd],eax
resend:
ret
global Choicem
Choicem: fld dword [aedge5]
fstp dword [aedge]
fld dword [bedge5]
fstp dword [bedge]
fld dword [xdelta5]
fstp dword [xdelta]
fld dword [ydelta5]
fstp dword [ydelta]
mov dword [fractaltype],MANDELBROT
call Mandelbrot
ret
global _Cycle
_Cycle:
Loopc0: mov eax,[cyinc]
mul dword [cydir]
add [off],eax
mov dword [pixel],0
Loopc: mov ebx,[pixel]
mov ecx,[imaged+ebx]
mov [count],ecx
cmp dword [count],0
je ok3
mov eax,[off]
add [count],eax
mov eax,[count]
mov edx,0
idiv dword [ncols]
mov [count],edx
add dword [count],1
ok3: mov eax,[count]
imul eax,3
add eax,2
mov cl,[Colors+eax]
sub eax,1
mov ebx,[pixel]
mov [im+ebx],cl
add dword [pixel],1
mov cl,[Colors+eax]
sub eax,1
mov ebx,[pixel]
mov [im+ebx],cl
add dword [pixel],1
mov cl,[Colors+eax]
mov ebx,[pixel]
mov [im+ebx],cl
add dword [pixel],1
add dword [pixel],1 ; 32-bit image buffer instead of 24
mov eax,[numpixels]
cmp [pixel],eax
jl Loopc
ret