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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
|
;;STRUC--Stucture Macro Library
;;Optimizing Version 2.30 03/31/87
if1
$NoConj equ 0
$And equ 1
$Or equ 2
$Short equ 3
$Near equ 4
$NearToShort equ 5
$ncxz equ 6
$AndOr = 0
$Temp = 0
$Temp2 = 0
$Dist = 0
$NoType equ 10
$ConjIfType equ 11
$IfType equ 12
$ElseType equ 13
$WhileType equ 14
$ConjWhileType equ 15
$RepeatType equ 16
$ConjUntilType equ 17
$ForType equ 18
$ConjLeaveType equ 19
$SelectType equ 20
$WhenType equ 21
$ConjWhenType equ 22
$OtherwiseType equ $ElseType
$StrucError macro text
Structure error -- text
endm
J macro
endm
JN macro
endm
$BuildJump macro j1,j2
j1 macro t
.xcref j1
j2 t
endm
endm
irp x,<<jeq,je>,<jlt,jl>,<jgt,jg>,<jneq,jne>,<jnlt,jnl>,<jngt,jng>,<jnpe,jpo>,<jnpo,jpe>>
$BuildJump x
endm
irp x,<<jzero,jz>,<jnzero,jnz>,<jnonzero,jnz>,<jnnonzero,jz>,<jand,jnz>,<jnand,jz>,<jnnand,jnz>>
$BuildJump x
endm
irp x,<a,ae,b,be,c,e,g,ge,l,le,o,p,s,z,cxz>
$BuildJump jnn&x,j&x
endm
jncxz macro t
if $Dist eq $NearToShort
jcxz $+5
jmp t
else
jcxz $+4
jmp short t
endif
endm
purge $BuildJump
$GetConj macro p1,p2
$AndOr = $NoConj
irp parm,<p1,p2>
ifnb <&parm>
irp x,<and,AND,or,OR>
ifidn <parm>,<x>
$AndOr = $&&&x
exitm
endif
endm
endif
endm
endm
$GetDist macro p1,p2
irp parm,<p1,p2>
ifnb <parm>
irp x,<short,SHORT,near,NEAR>
ifidn <parm>,<x>
$Dist = $&&&x
exitm
endif
endm
endif
endm
endm
$Poke macro n,m
$st&n = m
.xcref $st&n
endm
$Peek macro x,n
x = $st&n
endm
$Push macro n
$st = $st+1
$Poke %$st,n
endm
$Pop macro x
if $st gt 0
$Peek x,%$st
$st = $st-1
else
$StrucError <open structure>
endif
endm
$EquateLabel macro last,this
if $LastLabelOrg eq $
$ll&last = this
.xcref $ll&last
endif
endm
$TraceLabel macro n,a,b
if $ll&a eq $ll&b
$ll&n = b
.xcref $ll&n
else
$TraceLabel n,%$ll&a,%$ll&b
endif
endm
$Label macro n
if1
$EquateLabel %$LastLabel,n
$ll&n = n
.xcref $ll&n
$LastLabel = n
$LastLabelOrg = $
$l&n:
else
if $ll&n eq n
$l&n:
else
.xcref $l&n
.xcref $ll&n
endif
endif
endm
$CondJump macro l,tf,c
if1
ifb <c>
$EquateLabel %$LastLabel,l
endif
ifndef <$ll&l>
$ll&l = l
.xcref $ll&l
endif
else
$TraceLabel l,l,%$ll&l
endif
$CondJump2 %$ll&l,tf,c
endm
$CondJump2 macro l,tf,c
if $Dist eq $Short
ifb <c>
jmp short $l&l
else
ifidn <tf>,<f>
jn&c $l&l
else
j&c $l&l
endif
endif
else
ifnb <c>
ifdef $l&l
if (($ - $l&l) le 126) and (($l&l - $) le 129)
$Dist = $NearToShort
$nops = 3
ifidn <tf>,<f>
jn&c $l&l
ifdef $n&c
if $n&c eq $ncxz
$nops = 0
endif
endif
ifdef $&c
if $&c eq $ncxz
$nops = 5
endif
endif
else
j&c $l&l
ifdef $n&c
if $n&c eq $ncxz
$nops = 5
endif
endif
ifdef $&c
if $&c eq $ncxz
$nops = 0
endif
endif
endif
rept $nops
nop
endm
else
ifidn <tf>,<f>
j&c $+5
else
jn&c $+5
endif
jmp $l&l
endif
else
ifidn <tf>,<f>
j&c $+5
else
jn&c $+5
endif
jmp $l&l
endif
else
ifdef $l&l
ifidn <tf>,<NoFold>
jmp $l&l
else
if (($ - $l&l) le 126) and (($l&l - $) le 129)
jmp short $l&l
nop
else
jmp $l&l
endif
endif
else
jmp $l&l
endif
endif
endif
endm
$CondLoop macro l,c
loop&c $l&l
endm
$Test macro tgt,a1,a2,a3,a4,x
ifb <a1>
$StrucError <invalid condition>
else
ifb <a2>
$CondJump %&tgt,a1
else
ifb <a3>
ifdif <a1>,<zero>
ifdif <a1>,<nonzero>
ifdif <a1>,<ZERO>
ifdif <a1>,<NONZERO>
$StrucError <invalid condition>
exitm
endif
endif
endif
endif
or a2,a2
$CondJump %&tgt,a1
else
ifb <a4>
cmp a1,a3
$CondJump %&tgt,a2
else
ifb <x>
ifdif <a1>,<bit>
ifdif <a1>,<BIT>
$StrucError <invalid condition>
exitm
endif
endif
test a2,a4
$CondJump %&tgt,a3
else
$StrucError <invalid condition>
endif
endif
endif
endif
endif
endm
$TopTest macro args,n,c,p4,p5
$GetConj p4,p5
$Dist = $DefDist
$GetDist p4,p5
if $AndOr eq $NoConj
$Test <$sn-1,f>,args
$Pop $Temp
if $OrFound
$Label %$Temp
endif
$Push n
else
if $AndOr eq $And
$Test <$sn-1,f>,args
else
$OrFound = 1
$Test <$sn,t>,args
endif
$Push c
endif
endm
;;*****************************************************************************
.if macro t,p2,p3
$Peek $Temp,%$st
if $Temp eq $ConjIfType
$Pop $Temp
else
$OrFound = 0
$sn = $sn+1
$Push $sn
$sn = $sn+1
$Push $sn
$sn = $sn+1
$Push $sn
endif
$TopTest <t>,$IfType,$ConjIfType,p2,p3
endm
;;*****************************************************************************
.then macro
$Peek $Temp,%$st
if $Temp ne $IfType
if $Temp ne $WhenType
$StrucError <then without if or when>
endif
endif
endm
;;*****************************************************************************
.elseif macro t,p2,p3
$Pop $Temp
if $Temp ne $IfType
$StrucError <elseif without if>
exitm
endif
$OrFound = 0
$Pop $Temp
$Peek $Temp2,%$st
$Dist = $Near
$CondJump %$Temp2
$Label %$Temp
$sn = $sn+1
$Push $sn
$sn = $sn+1
$Push $sn
$TopTest <t>,$IfType,$ConjIfType,p2,p3
endm
;;*****************************************************************************
.else macro dist
$Pop $Temp
if $Temp ne $IfType
if $Temp ne $WhenType
if $Temp ne $SelectType
$StrucError <else without if, when or select>
exitm
endif
endif
endif
$sn = $sn+1
if $Temp eq $SelectType
$Push $sn
else
$Dist = $DefDist
$GetDist dist
$CondJump %$sn
$Pop $Temp
$Label %$Temp
$Push $sn
endif
$push $ElseType
endm
;;*****************************************************************************
.endif macro
$Pop $Temp
if $Temp ne $IfType
if $Temp ne $ElseType
$StrucError <endif without if>
exitm
endif
endif
$Pop $Temp
$Label %$Temp
$Pop $Temp
$Label %$Temp
endm
;;*****************************************************************************
.select macro x
$OrFound = 0
$sn = $sn+1
$Push $sn
$Push $SelectType
endm
;;*****************************************************************************
.when macro tst,p2,p3
$Pop $Temp
if $Temp ne $SelectType
if $Temp ne $WhenType
if $Temp ne $ConjWhenType
$StrucError <when without select>
exitm
endif
endif
endif
if $Temp ne $ConjWhenType
$Dist = $Near
$OrFound = 0
if $Temp eq $WhenType
$Pop $Temp2
$Peek $Temp,%$st
$CondJump %$Temp
$Label %$Temp2
endif
$sn = $sn+1
$Push $sn
$sn = $sn+1
$Push $sn
endif
$TopTest <tst>,$WhenType,$ConjWhenType,p2,p3
endm
;;*****************************************************************************
.otherwise macro dist
$Pop $Temp
if $Temp ne $WhenType
if $Temp ne $SelectType
if $Temp ne $IfType
$StrucError <otherwise without if, when or select>
exitm
endif
endif
endif
$sn = $sn+1
if $Temp eq $SelectType
$Push $sn
else
$Dist = $DefDist
$GetDist dist
$CondJump %$sn
$Pop $Temp
$Label %$Temp
$Push $sn
endif
$push $OtherwiseType
endm
;;*****************************************************************************
.endselect macro
$Pop $Temp
if $Temp ne $WhenType
if $Temp ne $OtherwiseType
if $Temp ne $SelectType
$StrucError <endselect without select>
exitm
endif
endif
endif
$pop $Temp2
if $Temp ne $SelectType
$Label %$Temp2
$Pop $Temp2
$Label %$Temp2
endif
endm
;;*****************************************************************************
.while macro t,p2,p3
$Peek $Temp,%$st
if $Temp eq $ConjWhileType
$Pop $Temp
else
$Push $LoopEnd
$OrFound = 0
$sn = $sn + 1
$Push $sn
$Label %$sn
$sn = $sn + 2
$Push $sn
$LoopEnd = $sn - 1
endif
$TopTest <t>,$WhileType,$ConjWhileType,p2,p3
endm
;;*****************************************************************************
.endwhile macro p1
$Pop $Temp
if $Temp ne $WhileType
$StrucError <endwhile without while>
exitm
endif
$Dist = $Near
$Pop $Temp
$CondJump %$Temp,NoFold
$Label %$Temp+1
$Pop $LoopEnd
endm
;;*****************************************************************************
.repeat macro
$Push $LoopEnd
$Push $LeaveFound
$sn = $sn+1
$Label %$sn
$Push $sn
$Push $RepeatType
$sn = $sn+1
$LoopEnd = $sn
$LeaveFound = 0
endm
;;*****************************************************************************
.until macro t,p2,p3
$until2 p2,p3,t
endm
$until2 macro p2,p3,a1,a2,a3,a4,x
$Pop $Temp
if $Temp ne $RepeatType
if $Temp ne $ConjUntilType
$StrucError <until without repeat>
exitm
endif
else
$OrFound = 0
endif
$Dist = $DefDist
$GetDist p2,p3
$GetConj p2,p3
if $AndOr eq $NoConj
$Pop $Temp
ifb <a1>
$Dist = $Near
$CondJump %$Temp,NoFold
else
$Test <$Temp,f>,<a1>,<a2>,<a3>,<a4>,<x>
endif
if $OrFound or $LeaveFound
$Label %$Temp+1
endif
$Pop $LeaveFound
$Pop $LoopEnd
else
$Peek $Temp,%$st
if $AndOr eq $And
$Test <$Temp,f>,<a1>,<a2>,<a3>,<a4>,<x>
else
$OrFound = 1
$Test <$Temp+1,t>,<a1>,<a2>,<a3>,<a4>,<x>
endif
$Push $ConjUntilType
endif
endm
;;*****************************************************************************
.loop macro cond
$Pop $Temp
if $Temp ne $RepeatType
$StrucError <loop without repeat>
exitm
endif
$Pop $Temp
$CondLoop %$Temp,cond
if $LeaveFound
$Label %$Temp+1
endif
$Pop $LeaveFound
$Pop $LoopEnd
endm
;;*****************************************************************************
.for macro index,equals,start,to,stop,by,step,dist
mov index,start
$Push $LoopEnd
$sn = $sn+1
$Push $sn
$Label %$sn
$sn = $sn+1
$LoopEnd = $sn
cmp index,stop
$Dist = $DefDist
ifb <step>
$Push 1
$GetDist by
$CondJump %$sn,t,gt
else
$GetDist dist
$Push %(step)
if step lt 0
$CondJump %$sn,t,lt
else
$CondJump %$sn,t,gt
endif
endif
$Push $ForType
endm
;;*****************************************************************************
.next macro index,dist
$Pop $Temp
if $Temp ne $ForType
$StrucError <next without for>
exitm
endif
$Pop $Temp
if $Temp eq 1
inc index
else
if $Temp eq -1
dec index
else
add index,$Temp
endif
endif
$Pop $Temp
$Dist = $Near
$CondJump %$Temp,NoFold
$Label %$Temp+1
$Pop $LoopEnd
endm
;;*****************************************************************************
.leave macro t,p2,p3
$leave2 p2,p3,t
endm
$leave2 macro p2,p3,a1,a2,a3,a4,x
ife $LoopEnd
$StrucError <leave outside a loop>
exitm
endif
$LeaveFound = 1
$Peek $Temp,%$st
if $Temp eq $ConjLeaveType
$Pop $Temp
else
$OrFound = 0
$sn = $sn + 1
endif
$Dist = 0
$GetDist <a1>
if $Dist
$CondJump %$LoopEnd
if $OrFound
$Label %$sn
endif
else
$Dist = $DefDist
$GetDist p2,p3
$GetConj p2,p3
if $AndOr eq $NoConj
ifb <a1>
$CondJump %$LoopEnd,t
else
$Test <$LoopEnd,t>,<a1>,<a2>,<a3>,<a4>,<x>
endif
if $OrFound
$Label %$sn
endif
else
if $AndOr eq $And
$OrFound = 1
$Test <$sn,f>,<a1>,<a2>,<a3>,<a4>,<x>
else
$Test <$LoopEnd,t>,<a1>,<a2>,<a3>,<a4>,<x>
endif
$Push $ConjLeaveType
endif
endif
endm
;;*****************************************************************************
else ;else for if1
$Pop $Temp
;;if $Temp ne $NoType
if $st ne 0
$StrucError <open structure(s)>
endif
.xcref $NoConj,$And,$Or,$Short,$Near,$NearToShort,$AndOr,$Temp,$Temp2,$Dist
.xcref $NoType,$ConjIfType,$IfType,$ElseType,$WhileType,$ConjWhileType
.xcref $RepeatType,$ConjUntilType,$ForType,$ConjLeaveType,jncxz
.xcref $SelectType,$WhenType,$OtherwiseType,$ConjWhenType
.xcref jeq,jgt,jlt,jneq,jngt,jnlt,jnna,jnnae,jnnb,jnnbe,jnnc,jnncxz
.xcref jnne,jnng,jnnge,jnnl,jnnle,jnno,jnnp,jnns,jnnz,jnpe,jnpo,$BuildJump
.xcref $GetConj,$GetDist,$Poke,$Peek,$Push,$Pop,$Label,$CondJump,$CondLoop,$Test
.xcref $TopTest,$leave2,$until2,$StrucError,j,jn,jand,jnand,jnnand
.xcref jnnonzero,jnonzero,jnzero,jzero
.xcref $st,$sn,$OrFound,$LoopEnd,$LeaveFound,$DefDist
.xcref $LastLabel,$LastLabelOrg,$EquateLabel,$TraceLabel,$CondJump2,$ncxz
endif
$st = 0
$sn = 0
$OrFound = 0
$LoopEnd = 0
$LeaveFound = 0
$LastLabel = -1
$LastLabelOrg = $
$DefDist= $Short
$Push %$NoType
|