aboutsummaryrefslogtreecommitdiffstats
path: root/codepseudo.c
blob: 8d474de265d3fb729323b760a4145ef97885b385 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
/* codepseudo.c */
/*****************************************************************************/
/* AS-Portierung                                                             */
/*                                                                           */
/* Haeufiger benutzte Pseudo-Befehle                                         */
/*                                                                           */
/* Historie: 23. 5.1996 Grundsteinlegung                                     */
/*            7. 7.1998 Fix Zugriffe auf CharTransTable wg. signed chars     */
/*           18. 8.1998 BookKeeping-Aufrufe bei SPeicherreservierungen       */
/*                                                                           */
/*****************************************************************************/

#include "stdinc.h"
#include <string.h>

#include "nls.h"
#include "bpemu.h"
#include "endian.h"
#include "strutil.h"
#include "chunks.h"
#include "asmdef.h"
#include "asmsub.h"
#include "asmpars.h"
#include "asmallg.h"
#include "asmitree.h"

#include "codepseudo.h"


        int FindInst(void *Field, int Size, int Count)
BEGIN
   char *cptr,**ptr;

#ifdef OPT
   int l=0,r=Count-1,m,res;

   while (TRUE)
    BEGIN
     m=(l+r)>>1; cptr=((char *) Field)+(Size*m);
     ptr=(char**) cptr;
     res=strcmp(*ptr,OpPart);
     if (res==0) return m;
     else if (l==r) return -1;
     else if (res<0)
      BEGIN
       if (r-l==1) return -1; else l=m;
      END
     else r=m;
    END

#else
   int z,res;

   cptr=(char *) Field;
   for (z=0; z<Count; z++)
    BEGIN
     ptr=(char**) cptr;
     res=strcmp(*ptr,OpPart);
     if (res==0) return z;
     if (res>0) return -1;
     cptr+=Size;
    END
   return -1;
#endif
END      


	Boolean IsIndirect(char *Asc)
BEGIN
   int z,Level,l;

   if (((l=strlen(Asc))<=2) OR (Asc[0]!='(') OR (Asc[l-1]!=')')) return False;

   Level=0;
   for (z=1; z<=l-2; z++)
    BEGIN
     if (Asc[z]=='(') Level++;
     if (Asc[z]==')') Level--;
     if (Level<0) return False;
    END

   return True;
END


static enum{DSNone,DSConstant,DSSpace} DSFlag;
typedef Boolean (*TLayoutFunc)(
#ifdef __PROTOS__
                               char *Asc, Word *Cnt, Boolean Turn
#endif
                                                                 );

	static Boolean LayoutByte(char *Asc, Word *Cnt, Boolean Turn)
BEGIN
   Boolean Result;
   TempResult t;

   Result=False;

   if (strcmp(Asc,"?")==0)
    BEGIN
     if (DSFlag==DSConstant) WrError(1930);
     else
      BEGIN
       *Cnt=1; Result=True; DSFlag=DSSpace; CodeLen++;
      END
     return Result;
    END
   else
    BEGIN
     if (DSFlag==DSSpace)
      BEGIN
       WrError(1930); return Result;
      END
     else DSFlag=DSConstant;
    END

   FirstPassUnknown=False; EvalExpression(Asc,&t);
   switch (t.Typ)
    BEGIN
     case TempInt:
      if (FirstPassUnknown) t.Contents.Int&=0xff;
      if (NOT RangeCheck(t.Contents.Int,Int8)) WrError(1320);
      else
       BEGIN
	BAsmCode[CodeLen++]=t.Contents.Int; *Cnt=1;
        Result=True;
       END;
      break;
     case TempFloat: 
      WrError(1135);
      break;
     case TempString:
      TranslateString(t.Contents.Ascii);
      memcpy(BAsmCode+CodeLen,t.Contents.Ascii,strlen(t.Contents.Ascii));
      CodeLen+=(*Cnt=strlen(t.Contents.Ascii));
      Result=True;
      break;
     case TempNone:
      break;
    END

   return Result;
END


	static Boolean LayoutWord(char *Asc, Word *Cnt, Boolean Turn)
BEGIN
   Boolean OK,Result;
   Word erg;

   *Cnt=2; Result=False;

   if (strcmp(Asc,"?")==0)
    BEGIN
     if (DSFlag==DSConstant) WrError(1930);
     else
      BEGIN
       Result=True; DSFlag=DSSpace; CodeLen+=2;
      END
     return Result;
    END
   else
    BEGIN
     if (DSFlag==DSSpace)
      BEGIN
       WrError(1930); return Result;
      END
     else DSFlag=DSConstant;
    END

   if (CodeLen+2>MaxCodeLen)
    BEGIN
     WrError(1920); return Result;
    END
   erg=EvalIntExpression(Asc,Int16,&OK);
   if (OK)
    BEGIN
     if (Turn) erg=((erg>>8)&0xff)+((erg&0xff)<<8);
     BAsmCode[CodeLen]=erg&0xff; BAsmCode[CodeLen+1]=erg>>8;
     CodeLen+=2;
    END
   return OK;
END


	static Boolean LayoutDoubleWord(char *Asc, Word *Cnt, Boolean Turn)
BEGIN
   TempResult erg;
   Boolean Result=False;

   *Cnt=4;

   if (strcmp(Asc,"?")==0)
    BEGIN
     if (DSFlag==DSConstant) WrError(1930);
     else 
      BEGIN
       Result=True; DSFlag=DSSpace; CodeLen+=4;
      END
     return Result;
    END
   else
    BEGIN
     if (DSFlag==DSSpace)
      BEGIN
       WrError(1930); return Result;
      END
     else DSFlag=DSConstant;
    END

   if (CodeLen+4>MaxCodeLen)
    BEGIN
     WrError(1920); return Result;
    END  

   KillBlanks(Asc); EvalExpression(Asc,&erg);
   switch (erg.Typ)
    BEGIN
     case TempNone: return Result;
     case TempInt:
      if (RangeCheck(erg.Contents.Int,Int32))
       BEGIN
        BAsmCode[CodeLen  ]=((erg.Contents.Int    )&0xff);
        BAsmCode[CodeLen+1]=((erg.Contents.Int>> 8)&0xff);
        BAsmCode[CodeLen+2]=((erg.Contents.Int>>16)&0xff);
        BAsmCode[CodeLen+3]=((erg.Contents.Int>>24)&0xff);
        CodeLen+=4;
       END
      else
       BEGIN
        WrError(1320);
        return Result;
       END
      break;
     case TempFloat:
      if (FloatRangeCheck(erg.Contents.Float,Float32))
       BEGIN
        Double_2_ieee4(erg.Contents.Float,BAsmCode+CodeLen,False);
	CodeLen+=4;
       END
      else
       BEGIN
        WrError(1320);
        return Result;
       END
      break;
     case TempString:
      WrError(1135);
      return Result;
    END

   if (Turn) DSwap(BAsmCode+CodeLen-4,4);
   return True;
END


	static Boolean LayoutQuadWord(char *Asc, Word *Cnt, Boolean Turn)
BEGIN
   Boolean Result;
   TempResult erg;
#ifndef HAS64
   int z;
#endif

   Result=False; *Cnt=8;

   if (strcmp(Asc,"?")==0)
    BEGIN
     if (DSFlag==DSConstant) WrError(1930);
     else
      BEGIN
       Result=True; DSFlag=DSSpace; CodeLen+=8;
      END
     return Result;
    END
   else
    BEGIN
     if (DSFlag==DSSpace)
      BEGIN
       WrError(1930); return Result;
      END
     else DSFlag=DSConstant;
    END

   if (CodeLen+8>MaxCodeLen)
    BEGIN
     WrError(1920); return Result;
    END

   KillBlanks(Asc); EvalExpression(Asc,&erg);
   switch(erg.Typ)
    BEGIN
     case TempNone:
      return Result;
     case TempInt:
      memcpy(BAsmCode+CodeLen,&(erg.Contents.Int),sizeof(LargeInt));
#ifdef HAS64
      if (BigEndian) QSwap(BAsmCode+CodeLen,8);
#else
      if (BigEndian) DSwap(BAsmCode+CodeLen,4);
      for (z=4; z<8; BAsmCode[CodeLen+(z++)]=(BAsmCode[CodeLen+3]>=0x80)?0xff:0x00);
#endif
      CodeLen+=8;
      break;
     case TempFloat:
      Double_2_ieee8(erg.Contents.Float,BAsmCode+CodeLen,False);
      CodeLen+=8;
      break;
     case TempString:
      WrError(1135);
      return Result;
    END
 
   if (Turn) QSwap(BAsmCode+CodeLen-8,8);
   return True;
END


	static Boolean LayoutTenBytes(char *Asc, Word *Cnt, Boolean Turn)
BEGIN
   Boolean OK,Result;
   Double erg;
   int z;
   Byte Exg;

   Result=False; *Cnt=10;

   if (strcmp(Asc,"?")==0)
    BEGIN
     if (DSFlag==DSConstant) WrError(1930);
     else
      BEGIN
       Result=True; DSFlag=DSSpace; CodeLen+=10;
      END
     return Result;
    END
   else
    BEGIN
     if (DSFlag==DSSpace)
      BEGIN
       WrError(1930); return Result;
      END
     else DSFlag=DSConstant;
    END

   if (CodeLen+10>MaxCodeLen)
    BEGIN
     WrError(1920); return Result;
    END
   erg=EvalFloatExpression(Asc,Float64,&OK);
   if (OK)
    BEGIN
     Double_2_ieee10(erg,BAsmCode+CodeLen,False);
     CodeLen+=10;
     if (Turn)
      for (z=0; z<5; z++)
       BEGIN
	Exg=BAsmCode[CodeLen-10+z];
	BAsmCode[CodeLen-10+z]=BAsmCode[CodeLen-1-z];
	BAsmCode[CodeLen-1-z]=Exg;
       END
    END
   return OK;
END


	static Boolean DecodeIntelPseudo_ValidSymChar(char ch)
BEGIN
   return (((ch>='A') AND (ch<='Z')) OR ((ch>='0') AND (ch<='9')) OR (ch=='_') OR (ch=='.'));
END

	static Boolean DecodeIntelPseudo_LayoutMult(char *Asc_O, Word *Cnt,
                                                    TLayoutFunc LayoutFunc,
                                                    Boolean Turn)
BEGIN
   int z,Depth,Fnd,ALen;
   String Asc,Part;
   Word SumCnt,ECnt,SInd;
   LongInt Rep;
   Boolean OK,Hyp;

   strmaxcpy(Asc,Asc_O,255);

   /* nach DUP suchen */

   Depth=0; Fnd=0; ALen=strlen(Asc);
   for (z=0; z<ALen-2; z++)
    BEGIN
     if (Asc[z]=='(') Depth++;
     else if (Asc[z]==')') Depth--;
     else if (Depth==0)
      if ( ((z==0) OR (NOT DecodeIntelPseudo_ValidSymChar(Asc[z-1])))
      AND  (NOT DecodeIntelPseudo_ValidSymChar(Asc[z+3]))
      AND (strncasecmp(Asc+z,"DUP",3)==0)) Fnd=z;
    END

   /* DUP gefunden: */

   if (Fnd!=0)
    BEGIN
     /* Anzahl ausrechnen */

     FirstPassUnknown=False;
     Asc[Fnd]='\0'; Rep=EvalIntExpression(Asc,Int32,&OK); Asc[Fnd]='D';
     if (FirstPassUnknown)
      BEGIN
       WrError(1820); return False;
      END
     if (NOT OK) return False;

     /* Nullargument vergessen, bei negativem warnen */

     if (Rep<0) WrError(270);
     if (Rep<=0) return True;

     /* Einzelteile bilden & evaluieren */

     strcpy(Asc,Asc+Fnd+3); KillPrefBlanks(Asc); SumCnt=0; 
     if ((strlen(Asc)>=2) AND (*Asc=='(') AND (Asc[strlen(Asc)-1]==')'))
      BEGIN
       strcpy(Asc,Asc+1); Asc[strlen(Asc)-1]='\0';
      END
     do
      BEGIN
       Fnd=0; z=0; Hyp=False; Depth=0;
       do
        BEGIN
         if (Asc[z]=='\'') Hyp=NOT Hyp;
         else if (NOT Hyp)
          BEGIN
           if (Asc[z]=='(') Depth++;
           else if (Asc[z]==')') Depth--;
           else if ((Depth==0) AND (Asc[z]==',')) Fnd=z;
          END
         z++;
        END
       while ((z<strlen(Asc)) AND (Fnd==0));
       if (Fnd==0)
        BEGIN
         strmaxcpy(Part,Asc,255); *Asc='\0';
        END
       else
        BEGIN
         Asc[Fnd]='\0'; strmaxcpy(Part,Asc,255);
         strcpy(Asc,Asc+Fnd+1);
        END
       if (NOT DecodeIntelPseudo_LayoutMult(Part,&ECnt,LayoutFunc,Turn))
        return False; 
       SumCnt+=ECnt;
      END
     while (*Asc!='\0');

     /* Ergebnis vervielfachen */

     if (DSFlag==DSConstant)
      BEGIN
       SInd=CodeLen-SumCnt;
       if (CodeLen+SumCnt*(Rep-1)>MaxCodeLen)
        BEGIN
         WrError(1920); return False;
        END
       for (z=1; z<=Rep-1; z++)
        BEGIN
         if (CodeLen+SumCnt>MaxCodeLen) return False;
         memcpy(BAsmCode+CodeLen,BAsmCode+SInd,SumCnt);
         CodeLen+=SumCnt;
        END
      END
     else CodeLen+=SumCnt*(Rep-1);
     *Cnt=SumCnt*Rep; return True;
    END

   /* kein DUP: einfacher Ausdruck */

   else return LayoutFunc(Asc,Cnt,Turn);
END

	Boolean DecodeIntelPseudo(Boolean Turn)
BEGIN
   Word Dummy;
   int z;
   TLayoutFunc LayoutFunc=Nil;
   Boolean OK;
   LongInt HVal;
   char Ident;

   if ((strlen(OpPart)!=2) OR (*OpPart!='D')) return False;
   Ident=OpPart[1];

   if ((Ident=='B') OR (Ident=='W') OR (Ident=='D') OR (Ident=='Q') OR (Ident=='T'))
    BEGIN
     DSFlag=DSNone;
     switch (Ident)
      BEGIN
       case 'B':
        LayoutFunc=LayoutByte;
        if (*LabPart!='\0') SetSymbolSize(LabPart,0);
        break;
       case 'W':
        LayoutFunc=LayoutWord;
        if (*LabPart!='\0') SetSymbolSize(LabPart,1);
        break;
       case 'D':
        LayoutFunc=LayoutDoubleWord;
        if (*LabPart!='\0') SetSymbolSize(LabPart,2);
        break;
       case 'Q':
        LayoutFunc=LayoutQuadWord;
        if (*LabPart!='\0') SetSymbolSize(LabPart,3);
        break;
       case 'T':
        LayoutFunc=LayoutTenBytes;
        if (*LabPart!='\0') SetSymbolSize(LabPart,4);
        break;
      END
     z=1;
     do
      BEGIN
       OK=DecodeIntelPseudo_LayoutMult(ArgStr[z],&Dummy,LayoutFunc,Turn);
       if (NOT OK) CodeLen=0;
       z++;
      END
     while ((OK) AND (z<=ArgCnt));
     DontPrint=(DSFlag==DSSpace);
     if (DontPrint) BookKeeping();
     if (OK) ActListGran=1;
     return True;
    END

   if (Ident=='S')
    BEGIN
     if (ArgCnt!=1) WrError(1110);
     else
      BEGIN
       FirstPassUnknown=False;
       HVal=EvalIntExpression(ArgStr[1],Int32,&OK);
       if (FirstPassUnknown) WrError(1820);
       else if (OK)
        BEGIN
         DontPrint=True; CodeLen=HVal;
         BookKeeping();
        END
      END
     return True;
    END

   return False;
END

/*--------------------------------------------------------------------------*/

static Boolean M16Turn=False;

	static Boolean CutRep(char *Asc, LongInt *Erg)
BEGIN
   char *p;
   Boolean OK;

   if (*Asc!='[')
    BEGIN
     *Erg=1; return True;
    END
   else
    BEGIN
     strcpy(Asc,Asc+1); p=QuotPos(Asc,']');
     if (p==Nil) 
      BEGIN
       WrError(1300); return False;
      END
     else
      BEGIN
       *p='\0';
       *Erg=EvalIntExpression(Asc,Int32,&OK);
       strcpy(Asc,p+1); return OK;
      END
    END
END	
	
	static void DecodeBYT(Word Index)
BEGIN
   int z;
   Boolean OK;
   TempResult t;
   LongInt Rep,z2;

   if (ArgCnt==0) WrError(1110);
   else
    BEGIN
     z=1; OK=True;
     do
      BEGIN
       KillBlanks(ArgStr[z]);
       OK=CutRep(ArgStr[z],&Rep);
       if (OK)
        BEGIN
         EvalExpression(ArgStr[z],&t);
         switch (t.Typ)
          BEGIN
           case TempInt:
            if (NOT RangeCheck(t.Contents.Int,Int8))
             BEGIN
              WrError(1320); OK=False;
             END
            else if (CodeLen+Rep>MaxCodeLen)
             BEGIN
              WrError(1920); OK=False;
             END
            else
             BEGIN
              memset(BAsmCode+CodeLen,t.Contents.Int,Rep);
              CodeLen+=Rep;
             END
            break;
           case TempFloat:
            WrError(1135); OK=False;
            break;
           case TempString:
            TranslateString(t.Contents.Ascii);
            if (CodeLen+Rep*strlen(t.Contents.Ascii)>MaxCodeLen)
             BEGIN
              WrError(1920); OK=False;
             END
            else for (z2=0; z2<Rep; z2++)
             BEGIN
              memcpy(BAsmCode+CodeLen,t.Contents.Ascii,strlen(t.Contents.Ascii));
              CodeLen+=strlen(t.Contents.Ascii);
             END
            break;
           default:
            OK=False; 
            break;
          END
        END  
       z++;
      END
     while ((z<=ArgCnt) AND (OK));
     if (NOT OK) CodeLen=0;
    END
END

	static void DecodeADR(Word Index)
BEGIN
   int z;
   Word HVal16;
   Boolean OK;
   LongInt Rep,z2;

   if (ArgCnt==0) WrError(1110);
   else
    BEGIN
     z=1; OK=True;
     do
      BEGIN
       OK=CutRep(ArgStr[z],&Rep);
       if (OK)
        if (CodeLen+(Rep<<1)>MaxCodeLen)
         BEGIN
          WrError(1920); OK=False;
         END
        else
         BEGIN
          HVal16=EvalIntExpression(ArgStr[z],Int16,&OK);
          if (OK)
           for (z2=0; z2<Rep; z2++)
            BEGIN
             if (M16Turn)
              BEGIN
               BAsmCode[CodeLen++]=Hi(HVal16);
               BAsmCode[CodeLen++]=Lo(HVal16);
              END
             else
              BEGIN
               BAsmCode[CodeLen++]=Lo(HVal16);
               BAsmCode[CodeLen++]=Hi(HVal16);
              END
           END
         END
       z++;
      END
     while ((z<=ArgCnt) AND (OK));
     if (NOT OK) CodeLen=0;
    END
END

	static void DecodeFCC(Word Index)
BEGIN
   String SVal;
   Boolean OK;
   int z;
   LongInt Rep,z2;

   if (ArgCnt==0) WrError(1110);
   else
    BEGIN
     z=1; OK=True;
     do
      BEGIN
       OK=CutRep(ArgStr[z],&Rep);
       if (OK)
        BEGIN
         EvalStringExpression(ArgStr[z],&OK,SVal);
         if (OK)
          if (CodeLen+Rep*strlen(SVal)>=MaxCodeLen)
           BEGIN
            WrError(1920); OK=False;
           END
          else
           BEGIN
            TranslateString(SVal);
            for (z2=0; z2<Rep; z2++)
             BEGIN
              memcpy(BAsmCode+CodeLen,SVal,strlen(SVal));
              CodeLen+=strlen(SVal);
             END
           END
        END   
       z++;
      END
     while ((z<=ArgCnt) AND (OK));
     if (NOT OK) CodeLen=0;
    END
END

	static void DecodeDFS(Word Index)
BEGIN
   Word HVal16;
   Boolean OK;

   if (ArgCnt!=1) WrError(1110);
   else
    BEGIN
     FirstPassUnknown=False;
     HVal16=EvalIntExpression(ArgStr[1],Int16,&OK);
     if (FirstPassUnknown) WrError(1820);
     else if (OK)
      BEGIN
       DontPrint=True; CodeLen=HVal16;
       BookKeeping();
      END
    END
END

	Boolean DecodeMotoPseudo(Boolean Turn)
BEGIN
   static PInstTable InstTable=Nil;

   if (InstTable==Nil)
    BEGIN
     InstTable=CreateInstTable(17);
     AddInstTable(InstTable,"BYT",0,DecodeBYT);
     AddInstTable(InstTable,"FCB",0,DecodeBYT);
     AddInstTable(InstTable,"ADR",0,DecodeADR);
     AddInstTable(InstTable,"FDB",0,DecodeADR);
     AddInstTable(InstTable,"FCC",0,DecodeFCC);
     AddInstTable(InstTable,"DFS",0,DecodeDFS);
     AddInstTable(InstTable,"RMB",0,DecodeDFS);
    END

   M16Turn=Turn;
   return LookupInstTable(InstTable,OpPart);
END

	static void DigIns(char Ch, Byte Pos, Word *w)
BEGIN
   Byte wpos=Pos>>2,bpos=(Pos&3)*4;
   Word dig=Ch-'0';

   w[wpos]|=(dig<<bpos);
END

       	void ConvertDec(Double F, Word *w)
BEGIN
   char s[30],Man[30],Exp[30];
   char *h;
   LongInt z;
   Byte epos;

   sprintf(s,"%0.16e",F); h=strchr(s,'e');
   if (h==Nil)
    BEGIN
     strcpy(Man,s); strcpy(Exp,"+0000");
    END
   else
    BEGIN
     *h='\0';
     strcpy(Man,s); strcpy(Exp,h+1);
    END
   memset(w,0,12);
   if (*Man=='-')
    BEGIN
     w[5]|=0x8000; strcpy(Man,Man+1);
    END
   else if (*Man=='+') strcpy(Man,Man+1);
   if (*Exp=='-')
    BEGIN
     w[5]|=0x4000; strcpy(Exp,Exp+1);
    END
   else if (*Exp=='+') strcpy(Exp,Exp+1);
   DigIns(*Man,16,w); strcpy(Man,Man+2);
   if (strlen(Man)>16) Man[16]='\0';
   for (z=0; z<strlen(Man); z++) DigIns(Man[z],15-z,w);
   if (strlen(Exp)>4) strcpy(Exp,Exp+strlen(Exp)-4);
   for (z=strlen(Exp)-1; z>=0; z--)
    BEGIN
     epos=strlen(Exp)-1-z;
     if (epos==3) DigIns(Exp[z],19,w); else DigIns(Exp[z],epos+20,w);
    END
END


        static void EnterByte(Byte b)
BEGIN
   if (((CodeLen&1)==1) AND (NOT BigEndian) AND (ListGran()!=1))
    BEGIN
     BAsmCode[CodeLen]=BAsmCode[CodeLen-1];
     BAsmCode[CodeLen-1]=b;
    END
   else
    BEGIN
     BAsmCode[CodeLen]=b;
    END
   CodeLen++;
END

	void AddMoto16PseudoONOFF(void)
BEGIN
   AddONOFF("PADDING",&DoPadding,DoPaddingName,False);
END

	Boolean DecodeMoto16Pseudo(ShortInt OpSize, Boolean Turn)
BEGIN
   Byte z;
   Word TurnField[8];
   char *zp;
   LongInt z2;
   LongInt WSize,Rep=0;
   LongInt NewPC,HVal,WLen;
#ifdef HAS64
   QuadInt QVal;
#endif
   Integer HVal16;
   Double DVal;
   TempResult t;
   Boolean OK,ValOK;

   if (OpSize<0) OpSize=1;

   if (*OpPart!='D') return False;

   if (Memo("DC"))
    BEGIN
     if (ArgCnt==0) WrError(1110);
     else
      BEGIN
       OK=True; z=1; WLen=0;
       do
        BEGIN
	 FirstPassUnknown=False;
	 OK=CutRep(ArgStr[z],&Rep);
	 if (OK)
	  if (FirstPassUnknown) WrError(1820);
	  else
	   BEGIN
	    switch (OpSize)
             BEGIN
	      case 0:
               FirstPassUnknown=False;
	       EvalExpression(ArgStr[z],&t);
               if ((FirstPassUnknown) AND (t.Typ==TempInt)) t.Contents.Int&=0xff;
	       switch (t.Typ)
                BEGIN
	         case TempInt:
                  if (NOT RangeCheck(t.Contents.Int,Int8))
	           BEGIN
		    WrError(1320); OK=False;
	           END
		  else if (CodeLen+Rep>MaxCodeLen)
	           BEGIN
		    WrError(1920); OK=False;
		   END
		  else for (z2=0; z2<Rep; z2++) EnterByte(t.Contents.Int);
                  break;
	         case TempFloat:
		  WrError(1135); OK=False;
		  break;
	         case TempString:
                  if (CodeLen+Rep*strlen(t.Contents.Ascii)>MaxCodeLen)
		   BEGIN
		    WrError(1920); OK=False;
	           END
		  else 
                   for (z2=0; z2<Rep; z2++)
	            for (zp=t.Contents.Ascii; *zp!='\0'; EnterByte(CharTransTable[((usint) *(zp++))&0xff]));
                  break;
	         default: OK=False;
	        END
	       break;
	      case 1:
	       HVal16=EvalIntExpression(ArgStr[z],Int16,&OK);
	       if (OK)
	        if (CodeLen+(Rep<<1)>MaxCodeLen)		
                 BEGIN
		  WrError(1920); OK=False;
		 END
	        else
                 BEGIN
                  if (ListGran()==1)
                   for (z2=0; z2<Rep; z2++)
                    BEGIN
                     BAsmCode[(WLen<<1)  ]=Hi(HVal16);
                     BAsmCode[(WLen<<1)+1]=Lo(HVal16);
                     WLen++;  
                    END
                  else
                   for (z2=0; z2<Rep; z2++) WAsmCode[WLen++]=HVal16; 
                  CodeLen+=Rep<<1;
		 END
	       break;
	      case 2:
	       HVal=EvalIntExpression(ArgStr[z],Int32,&OK);
	       if (OK)
	        if (CodeLen+(Rep<<2)>MaxCodeLen)
		 BEGIN
		  WrError(1920); OK=False;
		 END
	        else
		 BEGIN
                  if (ListGran()==1)
                   for (z2=0; z2<Rep; z2++)
                    BEGIN   
                     BAsmCode[(WLen<<1)  ]=(HVal >> 24) & 0xff;
                     BAsmCode[(WLen<<1)+1]=(HVal >> 16) & 0xff;
                     BAsmCode[(WLen<<1)+2]=(HVal >>  8) & 0xff;
                     BAsmCode[(WLen<<1)+3]=(HVal      ) & 0xff;
                     WLen+=2;
                    END
                  else
                   for (z2=0; z2<Rep; z2++)
                    BEGIN
		     WAsmCode[WLen++]=HVal >> 16;
		     WAsmCode[WLen++]=HVal & 0xffff;
                    END
                  CodeLen+=Rep<<2;
		 END
	       break;
#ifdef HAS64
	      case 3:
	       QVal=EvalIntExpression(ArgStr[z],Int64,&OK);
	       if (OK)
	        if (CodeLen+(Rep<<3)>MaxCodeLen)
		 BEGIN
		  WrError(1920); OK=False;
		 END
	        else
		 BEGIN
                  if (ListGran()==1)
                   for (z2=0; z2<Rep; z2++)
                    BEGIN
                     BAsmCode[(WLen<<1)  ]=(QVal >> 56) & 0xff;
                     BAsmCode[(WLen<<1)+1]=(QVal >> 48) & 0xff;
                     BAsmCode[(WLen<<1)+2]=(QVal >> 40) & 0xff;
                     BAsmCode[(WLen<<1)+3]=(QVal >> 32) & 0xff;
                     BAsmCode[(WLen<<1)+4]=(QVal >> 24) & 0xff;
                     BAsmCode[(WLen<<1)+5]=(QVal >> 16) & 0xff;
                     BAsmCode[(WLen<<1)+6]=(QVal >>  8) & 0xff;
                     BAsmCode[(WLen<<1)+7]=(QVal      ) & 0xff;
                     WLen+=4;
                    END
                  else
                   for (z2=0; z2<Rep; z2++)
                    BEGIN
		     WAsmCode[WLen++]=(QVal >> 48) & 0xffff;
                     WAsmCode[WLen++]=(QVal >> 32) & 0xffff;
                     WAsmCode[WLen++]=(QVal >> 16) & 0xffff;
		     WAsmCode[WLen++]=QVal & 0xffff;
                    END
                  CodeLen+=Rep<<3;
		 END
	       break;
#endif
	      case 4:
	       DVal=EvalFloatExpression(ArgStr[z],Float32,&OK);
	       if (OK)
	        if (CodeLen+(Rep<<2)>MaxCodeLen)
		 BEGIN
		  WrError(1920); OK=False;
		 END
	        else
		 BEGIN
                  Double_2_ieee4(DVal,(Byte *) TurnField,BigEndian); 
                  if (BigEndian) DWSwap((void*) TurnField,4);
                  if (ListGran()==1)
                   for (z2=0; z2<Rep; z2++)
                    BEGIN
                     BAsmCode[(WLen<<1)  ]=Hi(TurnField[1]);
                     BAsmCode[(WLen<<1)+1]=Lo(TurnField[1]);
                     BAsmCode[(WLen<<1)+2]=Hi(TurnField[0]);
                     BAsmCode[(WLen<<1)+3]=Lo(TurnField[0]);
                     WLen+=2;
                    END
                   else
                    for (z2=0; z2<Rep; z2++)
                    BEGIN
                     WAsmCode[WLen++]=TurnField[1];
                     WAsmCode[WLen++]=TurnField[0];
                    END
                  CodeLen+=Rep<<2;
		 END
	       break;
	      case 5:
	       DVal=EvalFloatExpression(ArgStr[z],Float64,&OK);
	       if (OK)
	        if (CodeLen+(Rep<<3)>MaxCodeLen)
		 BEGIN
		  WrError(1920); OK=False;
		 END
	        else
		 BEGIN
                  Double_2_ieee8(DVal,(Byte *) TurnField,BigEndian);
                  if (BigEndian) QWSwap((void *) TurnField,8);
                  if (ListGran()==1)
                   for (z2=0; z2<Rep; z2++)   
                    BEGIN
                     BAsmCode[(WLen<<1)  ]=Hi(TurnField[3]);
                     BAsmCode[(WLen<<1)+1]=Lo(TurnField[3]);
                     BAsmCode[(WLen<<1)+2]=Hi(TurnField[2]);
                     BAsmCode[(WLen<<1)+3]=Lo(TurnField[2]);
                     BAsmCode[(WLen<<1)+4]=Hi(TurnField[1]);
                     BAsmCode[(WLen<<1)+5]=Lo(TurnField[1]);
                     BAsmCode[(WLen<<1)+6]=Hi(TurnField[0]);
                     BAsmCode[(WLen<<1)+7]=Lo(TurnField[0]);
                     WLen+=4;
                    END
                  else
     		   for (z2=0; z2<Rep; z2++)
     		    BEGIN
     		     WAsmCode[WLen++]=TurnField[3];
     		     WAsmCode[WLen++]=TurnField[2];
     		     WAsmCode[WLen++]=TurnField[1];
     		     WAsmCode[WLen++]=TurnField[0];
     		    END
                  CodeLen+=Rep<<3;
		 END
	       break;
	      case 6:
	       DVal=EvalFloatExpression(ArgStr[z],Float64,&OK);
	       if (OK)
	        if (CodeLen+(Rep*12)>MaxCodeLen)
		 BEGIN
		  WrError(1920); OK=False;
		 END
	        else
		 BEGIN
		  Double_2_ieee10(DVal,(Byte *) TurnField,False);
                  if (BigEndian) WSwap((void *) TurnField,10);
                  if (ListGran()==1)
                   for (z2=0; z2<Rep; z2++)
                    BEGIN
                     BAsmCode[(WLen<<1)   ]=Hi(TurnField[4]);
                     BAsmCode[(WLen<<1)+ 1]=Lo(TurnField[4]);
                     BAsmCode[(WLen<<1)+ 2]=0;
                     BAsmCode[(WLen<<1)+ 3]=0;
                     BAsmCode[(WLen<<1)+ 4]=Hi(TurnField[3]);
                     BAsmCode[(WLen<<1)+ 5]=Lo(TurnField[3]);
                     BAsmCode[(WLen<<1)+ 6]=Hi(TurnField[2]);
                     BAsmCode[(WLen<<1)+ 7]=Lo(TurnField[2]);
                     BAsmCode[(WLen<<1)+ 8]=Hi(TurnField[1]);
                     BAsmCode[(WLen<<1)+ 9]=Lo(TurnField[1]);
                     BAsmCode[(WLen<<1)+10]=Hi(TurnField[0]);
                     BAsmCode[(WLen<<1)+11]=Lo(TurnField[0]);
                     WLen+=6;
                    END
                  else
		   for (z2=0; z2<Rep; z2++)
		    BEGIN
		     WAsmCode[WLen++]=TurnField[4];
		     WAsmCode[WLen++]=0;
		     WAsmCode[WLen++]=TurnField[3];
		     WAsmCode[WLen++]=TurnField[2];
		     WAsmCode[WLen++]=TurnField[1];
		     WAsmCode[WLen++]=TurnField[0];
		    END
                  CodeLen+=Rep*12;
		 END
	       break;
	      case 7:
	       DVal=EvalFloatExpression(ArgStr[z],Float64,&OK);
	       if (OK)
	        if (CodeLen+(Rep*12)>MaxCodeLen)
		 BEGIN
		  WrError(1920); OK=False;
		 END
	        else
		 BEGIN
		  ConvertDec(DVal,TurnField);
                  if (ListGran()==1)
                   for (z2=0; z2<Rep; z2++)
                    BEGIN
                     BAsmCode[(WLen<<1)   ]=Hi(TurnField[5]);
                     BAsmCode[(WLen<<1)+ 1]=Lo(TurnField[5]);
                     BAsmCode[(WLen<<1)+ 2]=Hi(TurnField[4]);
                     BAsmCode[(WLen<<1)+ 3]=Lo(TurnField[4]);
                     BAsmCode[(WLen<<1)+ 4]=Hi(TurnField[3]);
                     BAsmCode[(WLen<<1)+ 5]=Lo(TurnField[3]);
                     BAsmCode[(WLen<<1)+ 6]=Hi(TurnField[2]);
                     BAsmCode[(WLen<<1)+ 7]=Lo(TurnField[2]);
                     BAsmCode[(WLen<<1)+ 8]=Hi(TurnField[1]);
                     BAsmCode[(WLen<<1)+ 9]=Lo(TurnField[1]);
                     BAsmCode[(WLen<<1)+10]=Hi(TurnField[0]);
                     BAsmCode[(WLen<<1)+11]=Lo(TurnField[0]);
                     WLen+=6;
                    END
                  else
		   for (z2=0; z2<Rep; z2++)
		    BEGIN
		     WAsmCode[WLen++]=TurnField[5];
		     WAsmCode[WLen++]=TurnField[4];
		     WAsmCode[WLen++]=TurnField[3];
		     WAsmCode[WLen++]=TurnField[2];
		     WAsmCode[WLen++]=TurnField[1];
		     WAsmCode[WLen++]=TurnField[0];
		    END
                  CodeLen+=Rep*12;
		 END
	       break;
	     END
	   END
	 z++;
        END
       while ((z<=ArgCnt) AND (OK));
       if (NOT OK) CodeLen=0;
       if ((DoPadding) AND ((CodeLen&1)==1)) EnterByte(0);
      END
     return True;
    END

   if (Memo("DS"))
    BEGIN
     if (ArgCnt!=1) WrError(1110);
     else
      BEGIN
       FirstPassUnknown=False;
       HVal=EvalIntExpression(ArgStr[1],Int32,&ValOK);
       if (FirstPassUnknown) WrError(1820);
       if ((ValOK) AND (NOT FirstPassUnknown))
	BEGIN
	 DontPrint=True;
	 switch (OpSize)
          BEGIN
	   case 0: WSize=1; if (((HVal&1)==1) AND (DoPadding)) HVal++; break;
	   case 1: WSize=2; break;
	   case 2:
           case 4: WSize=4; break;
	   case 3:
           case 5: WSize=8; break;
	   case 6:
           case 7: WSize=12; break;
           default: WSize=0;
	  END
	 if (HVal==0)
	  BEGIN
	   NewPC=ProgCounter()+WSize-1;
	   NewPC=NewPC-(NewPC % WSize);
	   CodeLen=NewPC-ProgCounter();
	   if (CodeLen==0) DontPrint=False;
	  END
	 else CodeLen=HVal*WSize;
	 if (DontPrint) BookKeeping();
	END
      END
     return True;
    END

   return False;
END


	void CodeEquate(ShortInt DestSeg, LargeInt Min, LargeInt Max)
BEGIN
   Boolean OK;
   TempResult t;
   LargeInt Erg;

   FirstPassUnknown=False;
   if (ArgCnt!=1) WrError(1110);
   else
    BEGIN
     Erg=EvalIntExpression(ArgStr[1],Int32,&OK);
     if ((OK) AND (NOT FirstPassUnknown))
      if (Min>Erg) WrError(1315);
      else if (Erg>Max) WrError(1320);
      else
       BEGIN
	PushLocHandle(-1);
	EnterIntSymbol(LabPart,Erg,DestSeg,False);
	PopLocHandle();
	if (MakeUseList)
	 if (AddChunk(SegChunks+DestSeg,Erg,1,False)) WrError(90);
	t.Typ=TempInt; t.Contents.Int=Erg; SetListLineVal(&t);
       END
    END
END

	void CodeASSUME(ASSUMERec *Def, Integer Cnt)
BEGIN
   int z1,z2;
   Boolean OK;
   LongInt HVal;
   String RegPart,ValPart;

   if (ArgCnt==0) WrError(1110);
   else
    BEGIN
     z1=1; OK=True;
     while ((z1<=ArgCnt) AND (OK))
      BEGIN
       SplitString(ArgStr[z1],RegPart,ValPart,QuotPos(ArgStr[z1],':'));
       z2=0; NLS_UpString(RegPart);
       while ((z2<Cnt) AND (strcmp(Def[z2].Name,RegPart)!=0)) z2++;
       OK=(z2<Cnt);
       if (NOT OK) WrXError(1980,RegPart);
       else
	if (strcmp(ValPart,"NOTHING")==0)
	 if (Def[z2].NothingVal==-1) WrError(1350);
	 else *Def[z2].Dest=Def[z2].NothingVal;
	else
	 BEGIN
	  FirstPassUnknown=False;
	  HVal=EvalIntExpression(ValPart,Int32,&OK);
	  if (OK)
	   if (FirstPassUnknown)
	    BEGIN
	     WrError(1820); OK=False;
	    END
	   else if (ChkRange(HVal,Def[z2].Min,Def[z2].Max)) *Def[z2].Dest=HVal;
	 END
       z1++;
      END
    END
END

	void codepseudo_init(void)
BEGIN
END