-
Notifications
You must be signed in to change notification settings - Fork 0
/
CC1.ASM
4801 lines (4743 loc) · 72.6 KB
/
CC1.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
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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; -----------------------------------------------------------
; Small C Compiler for TRDOS 386 (v2.0.9 and later)
; Erdogan Tan - 2024
; Beginning: 05/09/2024
; Last Update: 29/09/2024
; -----------------------------------------------------------
; Derived from 'cc1.asm' file of KolibriOS SCC source code
; 2024
_nogo: TIMES 1 DD 0
_noloc: TIMES 1 DD 0
_opindex: TIMES 1 DD 0
_opsize: TIMES 1 DD 0
_swactive: TIMES 1 DD 0
_swdefaul: TIMES 1 DD 0
_swnext DD 0
_swend DD 0
_stage DD 0
_wq DD 0
_argcs: TIMES 1 DD 0
_argvs DD 0
_wqptr DD 0
_litptr: TIMES 1 DD 0
_macptr: TIMES 1 DD 0
_pptr: TIMES 1 DD 0
_ch: TIMES 1 DD 0
_nch: TIMES 1 DD 0
_declared: TIMES 1 DD 0
_iflevel: TIMES 1 DD 0
_skipleve: TIMES 1 DD 0
_nxtlab: TIMES 1 DD 0
_litlab: TIMES 1 DD 0
_csp: TIMES 1 DD 0
_argstk: TIMES 1 DD 0
_argtop: TIMES 1 DD 0
_ncmp: TIMES 1 DD 0
_errflag: TIMES 1 DD 0
_eof: TIMES 1 DD 0
_output: TIMES 1 DD 0
_files: TIMES 1 DD 0
_filearg DD 0
_input DD -1
_input2 DD -1
_usexpr DD 1
_ccode DD 1
_snext DD 0
_stail DD 0
_slast DD 0
_listfp: TIMES 1 DD 0
_lastst: TIMES 1 DD 0
_oldseg: TIMES 1 DD 0
_optimize: TIMES 1 DB 0
_alarm: TIMES 1 DB 0
_monitor: TIMES 1 DB 0
_pause: TIMES 1 DB 0
_symtab DD 0
_litq DD 0
_macn DD 0
_macq DD 0
_pline DD 0
_mline DD 0
_line DD 0
_lptr DD 0
_glbptr DD 0
_locptr DD 0
_quote DB 34
TIMES 1 DB 0
_cptr DD 0
_cptr2 DD 0
_cptr3 DD 0
_msname: TIMES 9 DB 0
_ssname: TIMES 9 DB 0
_op DD 57,73,3,20,55,43,22,47,35,7
DD 6,1,69,52,16,49
_op2 DD 57,73,3,20,55,44,23,48,36,7
DD 6,1,69,53,17,50
; TRDOS 386 modification
; 11/09/2024 (fputs -> puts)
_main:
PUSH EBP
MOV EBP,ESP
LEA EBX,[EBP+12]
MOV EAX,[EBX]
; TRDOS 386 modification
CMP EAX,1
JA short _main_@
MOV EAX,TVERSION
PUSH EAX
call _puts
POP EAX
JMP _1_483 ; usage
_main_@:
MOV DWORD [_argcs],EAX ; argc; (value)
LEA EBX,[EBP+8]
MOV EAX,[EBX]
MOV DWORD [_argvs],EAX ; argv; (address)
MOV EAX,VERSION
PUSH EAX
MOV CL,1
CALL _puts
;ADD ESP,4
POP EAX
MOV EAX,CRIGHT1
PUSH EAX
MOV CL,1
CALL _puts
;ADD ESP,4
POP EAX
MOV EAX,CRIGHT2
PUSH EAX
MOV CL,1
CALL _puts
;ADD ESP,4
POP EAX
MOV EAX,360 ; SWTABSZ (Note: It would be 90*8!) (*)
PUSH EAX ; 90*4 (90*SWSIZ) (*)
MOV EAX,1
PUSH EAX
MOV CL,2
CALL _OS_calloc
ADD ESP,8
MOV DWORD [_swnext],EAX
;
; ; swend = swnext+(SWTABSZ-SWSIZ);
;;MOV EAX,[_swnext]
;;MOV EBX,1424
;;ADD EAX,EBX ; 4*356
;ADD EAX,1424 ; This may be compiler expression defect!?
; TRDOS 386 Modification - 23/09/2024
; Note: SWSIZ was 2*BPW (16 bit label ptr + value ptr)
; but, I think.. (*)
; It must be 2*BPD = 8 (32 bit label ptr + value ptr)
; Erdogan Tan - 23/09/2024
;ADD EAX,356 ; SWTABSZ-SWSIZ
ADD EAX,352 ; SWTABSZ-8
MOV DWORD [_swend],EAX
;
MOV EAX,200 ; STAGESIZE
PUSH EAX
MOV EAX,8 ; 2*INTSIZE
PUSH EAX
MOV CL,2
CALL _OS_calloc
ADD ESP,8
MOV DWORD [_stage],EAX
MOV EAX,30 ; WQTABSZ
PUSH EAX
MOV EAX,4 ; INTSIZE
PUSH EAX
MOV CL,2
CALL _OS_calloc
ADD ESP,8
MOV DWORD [_wq],EAX
MOV DWORD [_wqptr],EAX
MOV EAX,3000 ; LITABSZ
PUSH EAX
MOV EAX,1
PUSH EAX
MOV CL,2
CALL _OS_calloc
ADD ESP,8
MOV DWORD [_litq],EAX
MOV EAX,3300 ; MACNSIZE = MACNBR*(NAMESIZE+2)
PUSH EAX ; MACNBR = 300 ; NAMESIZE = 9
MOV EAX,1
PUSH EAX
MOV CL,2
CALL _OS_calloc
ADD ESP,8
MOV DWORD [_macn],EAX
MOV EAX,2100 ; MACQSIZE = MACNBR*7
PUSH EAX
MOV EAX,1
PUSH EAX
MOV CL,2
CALL _OS_calloc
ADD ESP,8
MOV DWORD [_macq],EAX
MOV EAX,128 ; LINESIZE
PUSH EAX
MOV EAX,1
PUSH EAX
MOV CL,2
CALL _OS_calloc
ADD ESP,8
MOV DWORD [_pline],EAX
MOV EAX,128 ; LINESIZE
PUSH EAX
MOV EAX,1
PUSH EAX
MOV CL,2
CALL _OS_calloc
ADD ESP,8
MOV DWORD [_mline],EAX
MOV EAX,[_stage]
;
; ; slast = stage+(STAGESIZE*2*INTSIZE);
;;MOV EBX,6400
;;ADD EAX,EBX ; 1600*4 (STAGESIZE*2*INSIZE=1600)
;ADD EAX,6400 ; This may be compiler expression defect!?
; TRDOS 386 Modification - 23/09/2024
; Note:
; The expression result is seen as also multiplied by INTSIZE,
; the final result is 6400 (wrong!?)
; It must be 1600 (STAGESIZE*2*INTSIZE=1600)
; Erdogan Tan - 23/09/2024
ADD EAX,1600
;
MOV DWORD [_slast],EAX ; stage+(STAGESIZE*2*INTSIZE);
MOV EAX,4400 ; NUMLOCS*SYMAVG + NUMGLBS*SYMMAX
PUSH EAX ; 25*16 + 200*20
MOV EAX,1
PUSH EAX
MOV CL,2
CALL _OS_calloc
ADD ESP,8
MOV DWORD [_symtab],EAX
;MOV EAX,[_symtab] ; STARTLOC = symtab
MOV DWORD [_locptr],EAX ; STARTLOC
MOV EAX,[_symtab]
;MOV EBX,400
;ADD EAX,EBX ; ENDLOC = symtab+NUMLOCS*SYMAVG
ADD EAX,400 ; STARTGLB = ENDLOC
MOV DWORD [_glbptr],EAX ; STARTGLB
XOR CL,CL
CALL _ask
XOR CL,CL
CALL _openfile
XOR CL,CL
CALL _preprocess
XOR CL,CL
CALL _header
XOR CL,CL
CALL _setcodes
XOR CL,CL
CALL _parse
XOR CL,CL
CALL _trailer
MOV EAX,[_output]
PUSH EAX
MOV CL,1
CALL _OS_fclose
ADD ESP,4
POP EBP
RETN
VERSION: db "Small C 386/NT, Version 3.1, Revision Level 1",13,10,0
CRIGHT1: db "Copyright 1982-1998 J. E. Hendrix H T Walheim",13,10,0
CRIGHT2: db "TRDOS 386 Adaptation: Erdogan Tan - 2024",13,10,13,10,0
TVERSION: db "Small C Compiler v1.0 for TRDOS 386 v2",13,10
db "Erdogan Tan - 2024",13,10
NEWLINE:
crlf: db 13,10,0
_parse:
PUSH EBP
MOV EBP,ESP
_1_3:
MOV EAX,[_eof]
OR EAX,EAX
;JNZ short _1_4
JZ short _1_5
_1_4:
POP EBP
RETN
_1_5: ; if (amatch("extern", 6))
MOV EAX,_EXTERN_ ; _1_2+0
PUSH EAX
MOV EAX,6
PUSH EAX
MOV CL,2
CALL _amatch
ADD ESP,8
OR EAX,EAX
JZ short _1_6
_1_7:
MOV EAX,3 ; EXTERNAL
PUSH EAX
MOV CL,1
CALL _dodeclar ; dodeclare(EXTERNAL);
ADD ESP,4
JMP short _1_8
_1_6: ; else if(dodeclare(STATIC))
MOV EAX,2 ; STATIC
PUSH EAX
MOV CL,1
CALL _dodeclar ; dodeclare(STATIC)
ADD ESP,4
OR EAX,EAX
JNZ short _1_11
_1_9: ; else if(match("#asm"))
MOV EAX,_ASM_ ; _1_2+7
PUSH EAX
MOV CL,1
CALL _match ; match("#asm")
ADD ESP,4
OR EAX,EAX
JZ short _1_12
_1_13:
XOR CL,CL
CALL _doasm
JMP short _1_14
_1_12: ; else if(match("#include"))
MOV EAX,_INCLUD_ ; _1_2+12
PUSH EAX
MOV CL,1
CALL _match ; match("#include")
ADD ESP,4
OR EAX,EAX
JZ short _1_15
_1_16:
XOR CL,CL
CALL _doinclud ; doinclude();
JMP short _1_17
_1_15: ; else if(match("#define"))
MOV EAX,_DEFINE_ ; _1_2+21
PUSH EAX
MOV CL,1
CALL _match ; match("#define")
ADD ESP,4
OR EAX,EAX
JZ short _1_18
_1_19:
XOR CL,CL
CALL _dodefine ; dodefine();
JMP short _1_20
_1_18: ; else
XOR CL,CL
CALL _dofuncti ; dofunction();
_1_20:
_1_17:
_1_14:
_1_11:
_1_8:
XOR CL,CL
CALL _blanks ; blanks();
JMP _1_3
_1_2:
_EXTERN_:
DB "extern",0
_ASM_: DB "#asm",0
_INCLUD_:
DB "#include",0
_DEFINE_:
DB "#define",0
_dodeclar: ; dodeclare(class)
PUSH EBP
MOV EBP,ESP
MOV EAX,_CHAR_ ; _1_21+0
PUSH EAX
MOV EAX,4
PUSH EAX
MOV CL,2
CALL _amatch ; if (amatch("char",4))
ADD ESP,8
OR EAX,EAX
JZ short _1_22
_1_23:
MOV EAX,4 ; CHR
PUSH EAX
LEA EBX,[EBP+8]
MOV EAX,[EBX]
PUSH EAX
MOV CL,2
CALL _declglb ; declglb(CHR,class);
ADD ESP,8
JMP _1_24
_1_22: ; else if(amatch("unsigned",8))
MOV EAX,_UNSGND_ ; _1_21+5
PUSH EAX
MOV EAX,8
PUSH EAX
MOV CL,2
CALL _amatch ; if(amatch("unsigned", 8))
ADD ESP,8
OR EAX,EAX
JZ short _1_25
_1_26: ; & if(amatch("char",4)
MOV EAX,_CHAR_ ; _1_21+14
PUSH EAX
MOV EAX,4 ; CHR
PUSH EAX
MOV CL,2
CALL _amatch ; if(amatch("char",4))
ADD ESP,8
OR EAX,EAX
JZ short _1_27
_1_28:
MOV EAX,5 ; UCHR
PUSH EAX
LEA EBX,[EBP+8]
MOV EAX,[EBX]
PUSH EAX
MOV CL,2
CALL _declglb ; declglb(UCHR,class);
ADD ESP,8
;JMP short _1_29
JMP short _1_30
_1_27: ; else {amatch("int",3);
MOV EAX,_INT_ ; _1_21+19
PUSH EAX
MOV EAX,3
PUSH EAX
MOV CL,2
CALL _amatch ; amatch("int",3)
ADD ESP,8
MOV EAX,17 ; INT
PUSH EAX
LEA EBX,[EBP+8]
MOV EAX,[EBX]
PUSH EAX
MOV CL,2
CALL _declglb ; declglb(UINT, class);
ADD ESP,8
;_1_29:
JMP short _1_30
_1_25: ; else if(amatch("int",3)
MOV EAX,_INT_ ; _1_21+23
PUSH EAX
MOV EAX,3
PUSH EAX
MOV CL,2
CALL _amatch
ADD ESP,8
OR EAX,EAX
JNZ short _1_36
_1_34: ; || class == EXTERNAL)
LEA EAX,[EBP+8]
MOV EBX,[EAX]
MOV EAX,3 ; EXTERNAL
CALL __eq
OR EAX,EAX
JNZ short _1_36
_1_31: ; else return 0;
;XOR EAX,EAX
;eax = 0
POP EBP
RETN
_1_36: ; declglb(INT,class);
MOV EAX,16
PUSH EAX
LEA EBX,[EBP+8]
MOV EAX,[EBX]
PUSH EAX
MOV CL,2
CALL _declglb
ADD ESP,8
_1_30:
_1_24:
XOR CL,CL
CALL _ns ; ns();
MOV EAX,1 ; return 1;
POP EBP
RETN
_1_21:
_CHAR_: DB "char",0
_UNSGND_:
DB "unsigned",0
_INT_: DB "int",0
_declglb: ; declglb(type, class)
PUSH EBP
MOV EBP,ESP
ADD ESP,-8 ; int id, dim;
_1_39: ; while(1);
XOR CL,CL
CALL _endst ; if(endst())
OR EAX,EAX
JZ short _1_41
_1_42:
MOV ESP,EBP
POP EBP
RETN
_1_41:
MOV EAX,_STAR_ ; _1_38+0
PUSH EAX
MOV CL,1
CALL _match ; if(match("*"))
ADD ESP,4
OR EAX,EAX
JZ short _1_43
_1_44:
LEA EBX,[EBP-4]
MOV EAX,3 ; POINTER
MOV [EBX],EAX ; id = POINTER;
LEA EBX,[EBP-8]
XOR EAX,EAX
MOV [EBX],EAX ; dim = 0;
JMP short _1_45
_1_43: ; else
LEA EBX,[EBP-4]
MOV EAX,1 ; VARIABLE
MOV [EBX],EAX ; id = VARIABLE;
LEA EBX,[EBP-8]
;MOV EAX,1
MOV [EBX],EAX ; dim = 1;
_1_45:
MOV EAX,_ssname
PUSH EAX
MOV CL,1
CALL _symname ; if(symname(ssname) == 0)
ADD ESP,4
OR EAX,EAX
JNZ short _1_46
_1_47:
XOR CL,CL
CALL _illname ; illname();
_1_46:
MOV EAX,_ssname
PUSH EAX
MOV CL,1
CALL _findglb ; if(findglb(ssname))
ADD ESP,4
OR EAX,EAX
JZ short _1_48
_1_49:
MOV EAX,_ssname
PUSH EAX
MOV CL,1
CALL _multidef ; multidef(ssname);
;ADD ESP,4
POP EAX
_1_48:
LEA EAX,[EBP-4]
MOV EBX,[EAX] ; id
MOV EAX,1 ; VARIABLE
CALL __eq ; if(id == VARIABLE)
OR EAX,EAX
JZ short _1_50
_1_51:
MOV EAX,_LPARN_ ; _1_38+2
PUSH EAX
MOV CL,1
CALL _match ; if (match("("))
ADD ESP,4
OR EAX,EAX
JZ short _1_52
_1_53:
LEA EBX,[EBP-4]
MOV EAX,4
MOV [EBX],EAX ; id = FUNCTION;
MOV EAX,_RPARN_ ; _1_38+4
PUSH EAX
MOV CL,1
CALL _need ; need(")");
;ADD ESP,4
POP EAX
JMP short _1_54
_1_52:
MOV EAX,_LBRCK_ ;1_38+6
PUSH EAX
MOV CL,1
CALL _match ; else if(match("["))
ADD ESP,4
OR EAX,EAX
JZ short _1_55
_1_56:
LEA EBX,[EBP-4]
MOV EAX,2
MOV [EBX],EAX ; id = ARRAY;
LEA EAX,[EBP-8]
PUSH EAX
XOR CL,CL
CALL _needsub
POP EBX
MOV [EBX],EAX ; dim = needsub();
_1_55:
_1_54:
_1_50: ; if (class == EXTERNAL)
LEA EAX,[EBP+8]
MOV EBX,[EAX] ; class
MOV EAX,3 ; EXTERNAL
CALL __eq
OR EAX,EAX
JZ short _1_57
_1_58:
MOV EAX,_ssname
PUSH EAX ; sname
LEA EBX,[EBP+12]
MOV EAX,[EBX] ; type
MOV ECX,2
SAR EAX,CL
PUSH EAX ; type >> 2
LEA EBX,[EBP-4]
MOV EAX,[EBX]
PUSH EAX ; id
MOV CL,3
CALL _external ; external(ssname,type>>2,id);
ADD ESP,12
JMP short _1_59
_1_57: ; else if (id != FUNCTION)
LEA EAX,[EBP-4]
MOV EBX,[EAX]
MOV EAX,4 ; FUNCTION
CALL __ne
OR EAX,EAX
JZ short _1_60
_1_61:
LEA EBX,[EBP+12]
MOV EAX,[EBX] ; type
MOV ECX,2
SAR EAX,CL
PUSH EAX ; type >> 2
LEA EBX,[EBP-4]
MOV EAX,[EBX]
PUSH EAX ; id
LEA EBX,[EBP-8]
MOV EAX,[EBX]
PUSH EAX ; dim
MOV CL,3
CALL _initials ; initials(type >> 2, id, dim);
ADD ESP,12
_1_60:
_1_59: ; if(id == POINTER)
LEA EAX,[EBP-4]
MOV EBX,[EAX]
MOV EAX,3 ; POINTER
CALL __eq
OR EAX,EAX
JZ short _1_62
_1_63:
MOV EAX,_ssname
PUSH EAX ; ssname
LEA EBX,[EBP-4]
MOV EAX,[EBX]
PUSH EAX ; id
LEA EBX,[EBP+12]
MOV EAX,[EBX]
PUSH EAX ; type
MOV EAX,4
PUSH EAX ; PTRSIZE
XOR EAX,EAX
PUSH EAX ; 0
MOV EAX,_glbptr
PUSH EAX ; &glbptr
LEA EBX,[EBP+8]
MOV EAX,[EBX]
PUSH EAX ; class
;addsym(ssname,id,type,PTRSIZE,0,&glbptr,class);
MOV CL,7
CALL _addsym
ADD ESP,28
JMP short _1_64
_1_62: ; else
MOV EAX,_ssname
PUSH EAX ; ssname
LEA EBX,[EBP-4]
MOV EAX,[EBX]
PUSH EAX ; id
LEA EBX,[EBP+12]
MOV EAX,[EBX]
PUSH EAX ; type
LEA ECX,[EBP-8]
MOV EBX,[ECX] ; dim
;PUSH EBX
;LEA EBX,[EBP+12]
;MOV EAX,[EBX]
MOV ECX,2
SAR EAX,CL
;POP EBX
IMUL EBX
PUSH EAX ; dim*(type>>2)
XOR EAX,EAX
PUSH EAX ; 0
MOV EAX,_glbptr
PUSH EAX ; &glbptr
LEA EBX,[EBP+8]
MOV EAX,[EBX]
PUSH EAX ; class
; addsym(ssname,id,type,dim*(type>>2),0,&glbptr,class);
MOV CL,7
CALL _addsym
ADD ESP,28
_1_64:
MOV EAX,_COMMA_ ; _1_38+8
PUSH EAX
MOV CL,1
CALL _match ; if(match(",") == 0)
ADD ESP,4
OR EAX,EAX
JNZ short _1_65 ; jump to while(1)
_1_66: ; return;
MOV ESP,EBP
POP EBP
RETN
_1_65:
JMP _1_39
_1_38:
_STAR_ : DB "*",0
_LPARN_: DB "(",0
_RPARN_: DB ")",0
_LBRCK_: DB "[",0
_COMMA_: DB ",",0
_initials: ; initials(size, ident, dim)
PUSH EBP
MOV EBP,ESP
ADD ESP,-4 ; int savedim;
XOR EAX,EAX
MOV DWORD [_litptr],EAX ; litptr = 0;
LEA EBX,[EBP+8]
MOV EAX,[EBX]
OR EAX,EAX ; if(dim == 0) dim = -1;
JNZ short _1_68
_1_69:
LEA EBX,[EBP+8]
MOV EAX,-1
MOV [EBX],EAX ; dim = -1;
_1_68:
LEA EBX,[EBP+8]
MOV EAX,[EBX]
LEA EBX,[EBP-4]
MOV [EBX],EAX ; savedim = dim;
MOV EAX,_EQUAL_ ; _1_67+0
PUSH EAX
MOV CL,1
CALL _match ; if(match("=")) {
ADD ESP,4
OR EAX,EAX
JZ short _1_70
_1_71:
MOV EAX,_LBRACE_ ; _1_67+2
PUSH EAX
MOV CL,1
CALL _match ; if(match("{")) {
ADD ESP,4
OR EAX,EAX
JZ short _1_72 ; else
_1_73:
_1_74: ; while(dim) {
LEA EBX,[EBP+8]
MOV EAX,[EBX]
OR EAX,EAX
JZ short _1_75
_1_76:
LEA EBX,[EBP+16]
MOV EAX,[EBX]
PUSH EAX
LEA EBX,[EBP+12]
MOV EAX,[EBX]
PUSH EAX
LEA EAX,[EBP+8]
PUSH EAX
MOV CL,3
CALL _init ; init(size, ident, &dim);
ADD ESP,12
;MOV EAX,_COMMA2 ; _1_67+4
MOV EAX,_COMMA_
PUSH EAX
MOV CL,1
CALL _match ; if(match(",") == 0) break;
ADD ESP,4
OR EAX,EAX
JNZ short _1_74 ; jump to while(dim)
_1_75: ; break;
MOV EAX,_RBRACE_ ; _1_67+6
PUSH EAX
MOV CL,1
CALL _need ; need("}");
ADD ESP,4
JMP short _1_79
_1_72: ; else init(size, ident, &dim);
LEA EBX,[EBP+16]
MOV EAX,[EBX]
PUSH EAX
LEA EBX,[EBP+12]
MOV EAX,[EBX]
PUSH EAX
LEA EAX,[EBP+8]
PUSH EAX
MOV CL,3
CALL _init
ADD ESP,12
_1_79:
_1_70: ; if(savedim == -1 && dim == -1) {
LEA EAX,[EBP-4]
MOV EBX,[EAX]
MOV EAX,-1
CALL __eq
OR EAX,EAX
JZ short _1_80
_1_83:
LEA EAX,[EBP+8]
MOV EBX,[EAX]
MOV EAX,-1
CALL __eq
OR EAX,EAX
JZ short _1_80
_1_85: ; if(ident == ARRAY)
LEA EAX,[EBP+12]
MOV EBX,[EAX] ; ident
MOV EAX,2 ; ARRAY
CALL __eq
OR EAX,EAX
JZ short _1_86
_1_87:
MOV EAX,err_nas ; _1_67+8
PUSH EAX
MOV CL,1
CALL _error ; error("need array size");
;ADD ESP,4
POP EAX
_1_86:
XOR EAX,EAX
PUSH EAX
LEA EBX,[EBP+16]
MOV EAX,4 ; PTRSIZE
MOV [EBX],EAX ; size = PTRSIZE
PUSH EAX
MOV CL,2
CALL _stowlit ; stowlit(0, size = PTRSIZE);
ADD ESP,8
_1_80:
LEA EBX,[EBP+12]
MOV EAX,[EBX]
PUSH EAX
MOV CL,1
CALL _public ; public(ident); ;;; FASM
;ADD ESP,4
POP EAX
MOV EAX,[_litptr]
OR EAX,EAX ; if(litptr>0) dumplits(size);
JNG short _1_88 ; false
_1_89: ; true
LEA EBX,[EBP+16]
MOV EAX,[EBX]
PUSH EAX
MOV CL,1
CALL _dumplits ; dumplits(size);
;ADD ESP,4
POP EAX
JMP short _1_90
_1_88: ; else if(dim>0)
LEA EBX,[EBP+8]
MOV EAX,[EBX]
OR EAX,EAX
JNG short _1_91 ; false
_1_92: ; true
; In FASM: "<variable>: TIMES <number> D<type> 0"
MOV EAX,58
PUSH EAX
MOV EAX,[_output]
PUSH EAX
MOV CL,2
CALL _OS_fputc ; fputc(':',output);
ADD ESP,8
_1_91:
_1_90:
LEA EBX,[EBP+16]
MOV EAX,[EBX]
PUSH EAX
LEA EBX,[EBP+8]
MOV EAX,[EBX]
PUSH EAX
MOV CL,2
CALL _dumpzero ; dumpzero(size, dim);
ADD ESP,8
MOV ESP,EBP
POP EBP
RETN
_1_67:
_EQUAL_: DB "=",0 ; DB 61,0
_LBRACE_: DB "{",0 ; DB 123,0
;_COMMA2: DB ",",0 ; DB 44,0
_RBRACE_: DB "}",0 ; DB 125,0
err_nas: DB "need array size",0
_init: ; init(size, ident, dim)
PUSH EBP
MOV EBP,ESP
ADD ESP,-4 ; int value;
LEA EAX,[EBP-4]
PUSH EAX
MOV CL,1
CALL _string ; if(string(&value)) {
ADD ESP,4
OR EAX,EAX
JZ short _1_94
_1_95: ; if(ident == VARIABLE || size != 1)
LEA EAX,[EBP+12]
MOV EBX,[EAX]
MOV EAX,1
CALL __eq
OR EAX,EAX
JNZ short _1_101 ; ident == VARIABLE
_1_99:
LEA EAX,[EBP+16]
MOV EBX,[EAX]
MOV EAX,1
CALL __ne
OR EAX,EAX
JZ short _1_96 ; size = 1
_1_101: ; ident == VARIABLE || size != 1
; error("must assign to char pointer or char array");
MOV EAX,err_matcp ; _1_93+0
PUSH EAX
MOV CL,1
CALL _error
;ADD ESP,4
POP EAX
_1_96:
LEA EAX,[EBP+8]
MOV EBX,[EAX]
PUSH EBX ; DIM (address)
MOV EAX,[EBX]
PUSH EAX ; *DIM (value)
LEA EBX,[EBP-4]
MOV EAX,[EBX] ; value
MOV EBX,[_litptr]
SUB EBX,EAX ; litptr - value
POP EAX ; *DIM (value)
SUB EAX,EBX ;
POP EBX ; DIM (address)
MOV [EBX],EAX ; *dim -= (litptr - value);
LEA EAX,[EBP+12] ; if(ident == POINTER) point();
MOV EBX,[EAX]
MOV EAX,3 ; POINTER
CALL __eq
OR EAX,EAX
JZ short _1_104
_1_103: ; ident == POINTER
XOR CL,CL
CALL _point ; point();
_1_102:
JMP short _1_104
_1_94: ; else if(constexpr(&value)) {
LEA EAX,[EBP-4]
PUSH EAX
MOV CL,1
CALL _constexp
ADD ESP,4
OR EAX,EAX
JZ short _1_105 ; false
_1_106: ; if(ident == POINTER)
LEA EAX,[EBP+12]
MOV EBX,[EAX]
MOV EAX,3
CALL __eq
OR EAX,EAX
JZ short _1_107
_1_108:
MOV EAX,err_cnatp ; _1_93+42
PUSH EAX
MOV CL,1
CALL _error ; error("cannot assign to pointer");
;ADD ESP,4
POP EAX
_1_107:
LEA EBX,[EBP-4]
MOV EAX,[EBX]
PUSH EAX
LEA EBX,[EBP+16]
MOV EAX,[EBX]
PUSH EAX
MOV CL,2
CALL _stowlit ; stowlit(value, size);
ADD ESP,8
LEA EAX,[EBP+8]
MOV EBX,[EAX]
MOV EAX,[EBX]
;;MOV EBX,1
;;SUB EAX,EBX
;SUB EAX,1
DEC EAX
MOV [EBX],EAX ; *dim -= 1;
_1_105:
_1_104:
MOV ESP,EBP
POP EBP
RETN
_1_93:
err_matcp: DB "must assign to char pointer or char array",0
err_cnatp: DB "cannot assign to pointer",0
_needsub:
PUSH EBP
MOV EBP,ESP
ADD ESP,-4 ; int val;
; if(match("]")) return 0;
MOV EAX,_RBRCK_ ; _1_109+0
PUSH EAX
MOV CL,1
CALL _match
ADD ESP,4
OR EAX,EAX
JZ short _1_110