-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpalbart-2.4.c
More file actions
3895 lines (3495 loc) · 146 KB
/
palbart-2.4.c
File metadata and controls
3895 lines (3495 loc) · 146 KB
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
/******************************************************************************/
/* */
/* Program: PAL */
/* File: pal.c */
/* Author: Gary A. Messenbrink */
/* gam@rahul.net */
/* */
/* Purpose: A 2 pass PDP-8 pal-like assembler. */
/* */
/* PAL(1) */
/* */
/* NAME */
/* pal - a PDP/8 pal-like assembler. */
/* */
/* SYNOPSIS: */
/* pal [ -d -l -p -r -x ] inputfile */
/* */
/* DESCRIPTION */
/* This is a cross-assembler to for PDP/8 assembly language programs. */
/* It will produce an output file in bin format, rim format, and using the */
/* appropriate pseudo-ops, a combination of rim and bin formats. */
/* A listing file is always produced and with an optional symbol table */
/* and/or a symbol cross-reference (concordance). The permanent symbol */
/* table can be output in a form that may be read back in so a customized */
/* permanent symbol table can be produced. Any detected errors are output */
/* to a separate file giving the filename in which they were detected */
/* along with the line number, column number and error message as well as */
/* marking the error in the listing file. */
/* The following file name extensions are used: */
/* .pal source code (input) */
/* .lst assembly listing (output) */
/* .bin assembly output in DEC's bin format (output) */
/* .rim assembly output in DEC's rim format (output) */
/* .err assembly errors detected (if any) (output) */
/* .prm permanent symbol table in form suitable for reading after */
/* the EXPUNGE pseudo-op. */
/* */
/* OPTIONS */
/* -d Dump the symbol table at end of assembly */
/* -l Allow generation of literals (default is no literal generation) */
/* -p Generate a file with the permanent symbols in it. */
/* (To get the current symbol table, assemble a file than has only */
/* a $ in it.) */
/* -r Produce output in rim format (default is bin format) */
/* -x Generate a cross-reference (concordance) of user symbols. */
/* */
/* DIAGNOSTICS */
/* Assembler error diagnostics are output to an error file and inserted */
/* in the listing file. Each line in the error file has the form */
/* */
/* <filename>(<line>:<col>) : error: <message> at Loc = <loc> */
/* */
/* An example error message is: */
/* */
/* bintst.pal(17:9) : error: undefined symbol "UNDEF" at Loc = 07616 */
/* */
/* The error diagnostics put in the listing start with a two character */
/* error code (if appropriate) and a short message. A carat '^' is */
/* placed under the item in error if appropriate. */
/* An example error message is: */
/* */
/* 17 07616 3000 DCA UNDEF */
/* UD undefined ^ */
/* 18 07617 1777 TAD I DUMMY */
/* */
/* When an indirect is generated, an at character '@' is placed after the */
/* the instruction value in the listing as an indicator as follows: */
/* */
/* 14 03716 1777@ TAD OFFPAG */
/* */
/* Undefined symbols are marked in the symbol table listing by prepending */
/* a '?' to the symbol. Redefined symbols are marked in the symbol table */
/* listing by prepending a '#' to the symbol. Examples are: */
/* */
/* #REDEF 04567 */
/* SWITCH 07612 */
/* ?UNDEF 00000 */
/* */
/* Refer to the code for the diagnostic messages generated. */
/* */
/* BUGS */
/* Only a minimal effort has been made to keep the listing format */
/* anything like the PAL-8 listing format. */
/* The operation of the conditional assembly pseudo-ops may not function */
/* exactly as the DEC versions. I did not have any examples of these so */
/* the implementation is my interpretation of how they should work. */
/* */
/* The RIMPUNch and BINPUNch pseudo-ops do not change the binary output */
/* file type that was specified on startup. This was intentional and */
/* and allows rim formatted data to be output prior to the actual binary */
/* formatted data. On UN*X style systems, the same effect can be achieved */
/* by using the "cat" command, but on DOS/Windows systems, doing this was */
/* a major chore. */
/* */
/* The floating point input does not generate values exactly as the DEC */
/* compiler does. I worked out several examples by hand and believe that */
/* this implementation is slightly more accurate. If I am mistaken, */
/* let me know and, if possible, a better method of generating the values. */
/* */
/* BUILD and INSTALLATION */
/* This program has been built and successfully executed on: */
/* a. Linux (80486 CPU)using gcc */
/* b. RS/6000 (AIX 3.2.5) */
/* c. Borland C++ version 3.1 (large memory model) */
/* d. Borland C++ version 4.52 (large memory model) */
/* with no modifications to the source code. */
/* */
/* On UNIX type systems, store the the program as the pal command */
/* and on PC type systems, store it as pal.exe */
/* */
/* REFERENCES: */
/* This assembler is based on the pal assember by: */
/* Douglas Jones <jones@cs.uiowa.edu> and */
/* Rich Coon <coon@convexw.convex.com> */
/* */
/* DISCLAIMER: */
/* See the symbol table for the set of pseudo-ops supported. */
/* See the code for pseudo-ops that are not standard for PDP/8 assembly. */
/* Refer to DEC's "Programming Languages (for the PDP/8)" for complete */
/* documentation of pseudo-ops. */
/* Refer to DEC's "Introduction to Programming (for the PDP/8)" or a */
/* lower level introduction to the assembly language. */
/* */
/* WARRANTY: */
/* If you don't like it the way it works or if it doesn't work, that's */
/* tough. You're welcome to fix it yourself. That's what you get for */
/* using free software. */
/* */
/* COPYRIGHT NOTICE: */
/* This is free software. There is no fee for using it. You may make */
/* any changes that you wish and also give it away. If you can make */
/* a commercial product out of it, fine, but do not put any limits on */
/* the purchaser's right to do the same. If you improve it or fix any */
/* bugs, it would be nice if you told me and offered me a copy of the */
/* new version. */
/* */
/* */
/* Amendments Record: */
/* Version Date by Comments */
/* ------- ------- --- --------------------------------------------------- */
/* v1.0 12Apr96 GAM Original */
/* v1.1 18Nov96 GAM Permanent symbol table initialization error. */
/* v1.2 20Nov96 GAM Added BINPUNch and RIMPUNch pseudo-operators. */
/* v1.3 24Nov96 GAM Added DUBL pseudo-op (24 bit integer constants). */
/* v1.4 29Nov96 GAM Fixed bug in checksum generation. */
/* v2.1 08Dec96 GAM Added concordance processing (cross reference). */
/* v2.2 10Dec96 GAM Added FLTG psuedo-op (floating point constants). */
/* v2.3 2Feb97 GAM Fixed paging problem in cross reference output. */
/* v2.4 11Apr97 GAM Fixed problem with some labels being put in cross */
/* reference multiple times. */
/* */
/******************************************************************************/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *release = "pal-2.4, 11 April 1997";
#define LINELEN 96
#define LIST_LINES_PER_PAGE 55 /* Includes 5 line page header. */
#define NAMELEN 128
#define SYMBOL_COLUMNS 5
#define SYMLEN 7
#define SYMBOL_TABLE_SIZE 1024
#define TITLELEN 63
#define XREF_COLUMNS 8
#define ADDRESS_FIELD 00177
#define FIELD_FIELD 070000
#define INDIRECT_BIT 00400
#define LAST_PAGE_LOC 00177
#define OP_CODE 07000
#define PAGE_BIT 00200
#ifdef PAGE_SIZE
#undef PAGE_SIZE
#endif
#define PAGE_SIZE 00200
#define PAGE_FIELD 07600
#define PAGE_ZERO_END 00200
/* Macro to get the number of elements in an array. */
#define DIM(a) (sizeof(a)/sizeof(a[0]))
/* Macro to get the address plus one of the end of an array. */
#define BEYOND(a) ((a) + DIM(A))
#define is_blank(c) ((c==' ') || (c=='\t') || (c=='\f') || (c=='>'))
#define isend(c) ((c=='\0')|| (c=='\n'))
#define isdone(c) ((c=='/') || (isend(c)) || (c==';'))
/* Macros for testing symbol attributes. Each macro evaluates to non-zero */
/* (true) if the stated condtion is met. */
/* Use these to test attributes. The proper bits are extracted and then */
/* tested. */
#define M_CONDITIONAL(s) ((s & CONDITION) == CONDITION)
#define M_DEFINED(s) ((s & DEFINED) == DEFINED)
#define M_DUPLICATE(s) ((s & DUPLICATE) == DUPLICATE)
#define M_FIXED(s) ((s & FIXED) == FIXED)
#define M_LABEL(s) ((s & LABEL) == LABEL)
#define M_MRI(s) ((s & MRI) == MRI)
#define M_MRIFIX(s) ((s & MRIFIX) == MRIFIX)
#define M_PSEUDO(s) ((s & PSEUDO) == PSEUDO)
#define M_REDEFINED(s) ((s & REDEFINED) == REDEFINED)
#define M_UNDEFINED(s) (!M_DEFINED(s))
/* This macro is used to test symbols by the conditional assembly pseudo-ops. */
#define M_DEF(s) (M_DEFINED(s))
#define M_COND(s) (M_DEFINED(s))
#define M_DEFINED_CONDITIONALLY(t) ((M_DEF(t)&&pass==1)||(!M_COND(t)&&pass==2))
typedef unsigned char BOOL;
typedef unsigned char BYTE;
typedef short int WORD16;
typedef long int WORD32;
#ifndef FALSE
#define FALSE 0
#define TRUE (!FALSE)
#endif
/* Line listing styles. Used to control listing of lines. */
enum linestyle_t
{
LINE, LINE_VAL, LINE_LOC_VAL, LOC_VAL
};
typedef enum linestyle_t LINESTYLE_T;
/* Symbol Types. */
/* Note that the names that have FIX as the suffix contain the FIXED bit */
/* included in the value. */
/* */
/* The CONDITION bit is used when processing the conditional assembly PSEUDO- */
/* OPs (e.g., IFDEF). During pass 1 of the assembly, the symbol is either */
/* defined or undefined. The condition bit is set when the symbol is defined */
/* during pass 1 and reset on pass 2 at the location the symbol was defined */
/* during pass 1. When processing conditionals during pass 2, if the symbol */
/* is defined and the condition bit is set, the symbol is treated as if it */
/* were undefined. This gives consistent behavior of the conditional */
/* pseudo-ops during both pass 1 and pass 2. */
enum symtyp
{
UNDEFINED = 0000,
DEFINED = 0001,
FIXED = 0002,
MRI = 0004 | DEFINED,
LABEL = 0010 | DEFINED,
REDEFINED = 0020 | DEFINED,
DUPLICATE = 0040 | DEFINED,
PSEUDO = 0100 | FIXED | DEFINED,
CONDITION = 0200 | DEFINED,
MRIFIX = MRI | FIXED | DEFINED,
DEFFIX = DEFINED | FIXED
};
typedef enum symtyp SYMTYP;
enum pseudo_t
{
BANK, BINPUNCH, DECIMAL, DUBL, EJECT, ENPUNCH, EXPUNGE, FIELD,
FIXMRI, FIXTAB, FLTG, IFDEF, IFNDEF, IFNZERO, IFZERO, NOPUNCH,
OCTAL, PAGE, PAUSE, RELOC, RIMPUNCH, SEGMNT, TEXT, TITLE,
XLIST, ZBLOCK
};
typedef enum pseudo_t PSEUDO_T;
struct sym_t
{
SYMTYP type;
char name[SYMLEN];
WORD16 val;
int xref_index;
int xref_count;
};
typedef struct sym_t SYM_T;
struct lpool_t
{
BOOL error; /* True if error message has been printed. */
WORD16 loc;
WORD16 pool[PAGE_SIZE];
};
typedef struct lpool_t LPOOL_T;
struct emsg_t
{
char *list;
char *file;
};
typedef struct emsg_t EMSG_T;
struct errsave_t
{
char *mesg;
int col;
};
typedef struct errsave_t ERRSAVE_T;
struct fltg_
{
WORD16 exponent;
WORD32 mantissa;
};
typedef struct fltg_ FLTG_T;
/*----------------------------------------------------------------------------*/
/* Function Prototypes */
int binarySearch( char *name, int start, int symbol_count );
int compareSymbols( const void *a, const void *b );
void conditionFalse( void );
void conditionTrue( void );
SYM_T *defineLexeme( int start, int term, WORD16 val, SYMTYP type );
SYM_T *defineSymbol( char *name, WORD16 val, SYMTYP type, WORD16 start);
void endOfBinary( void );
void errorLexeme( EMSG_T *mesg, int col );
void errorMessage( EMSG_T *mesg, int col );
void errorSymbol( EMSG_T *mesg, char *name, int col );
SYM_T *eval( void );
WORD32 evalDubl( WORD32 initial_value );
FLTG_T *evalFltg( void );
SYM_T *evalSymbol( void );
void getArgs( int argc, char *argv[] );
WORD32 getDublExpr( void );
WORD32 getDublExprs( void );
FLTG_T *getFltgExpr( void );
FLTG_T *getFltgExprs( void );
SYM_T *getExpr( void );
WORD16 getExprs( void );
WORD16 incrementClc( void );
void inputDubl( void );
void inputFltg( void );
WORD16 insertLiteral( LPOOL_T *pool, WORD16 value );
char *lexemeToName( char *name, int from, int term );
void listLine( void );
SYM_T *lookup( char *name );
void moveToEndOfLine( void );
void nextLexBlank( void );
void nextLexeme( void );
void normalizeFltg( FLTG_T *fltg );
void onePass( void );
void printCrossReference( void );
void printErrorMessages( void );
void printLine(char *line, WORD16 loc, WORD16 val, LINESTYLE_T linestyle);
void printPageBreak( void );
void printPermanentSymbolTable( void );
void printSymbolTable( void );
BOOL pseudoOperators( PSEUDO_T val );
void punchChecksum( void );
void punchLocObject( WORD16 loc, WORD16 val );
void punchLiteralPool( LPOOL_T *p, WORD16 lpool_page );
void punchOutObject( WORD16 loc, WORD16 val );
void punchLeader( int count );
void punchObject( WORD16 val );
void punchOrigin( WORD16 loc );
void readLine( void );
void saveError( char *mesg, int cc );
BOOL testForLiteralCollision( WORD16 loc );
void topOfForm( char *title, char *sub_title );
/*----------------------------------------------------------------------------*/
/* Table of pseudo-ops (directives) which are used to setup the symbol */
/* table on startup and when the EXPUNGE pseudo-op is executed. */
SYM_T pseudo[] =
{
{ PSEUDO, "BANK", BANK }, /* Like field, select some 32K out of 128K*/
{ PSEUDO, "BINPUN", BINPUNCH }, /* Output in Binary Loader format. */
{ PSEUDO, "DECIMA", DECIMAL }, /* Read literal constants in base 10. */
{ PSEUDO, "DUBL", DUBL }, /* Ignored (unsupported). */
{ PSEUDO, "EJECT", EJECT }, /* Eject a page in the listing. */
{ PSEUDO, "ENPUNC", ENPUNCH }, /* Turn on object code generation. */
{ PSEUDO, "EXPUNG", EXPUNGE }, /* Remove all symbols from symbol table. */
{ PSEUDO, "FIELD", FIELD }, /* Set origin to memory field. */
{ PSEUDO, "FIXMRI", FIXMRI }, /* Like =, but creates mem ref instruction*/
{ PSEUDO, "FIXTAB", FIXTAB }, /* Mark current symbols as permanent. */
{ PSEUDO, "FLTG", FLTG }, /* Ignored (unsupported). */
{ PSEUDO, "IFDEF", IFDEF }, /* Assemble if symbol is defined. */
{ PSEUDO, "IFNDEF", IFNDEF }, /* Assemble if symbol is not defined. */
{ PSEUDO, "IFNZER", IFNZERO }, /* Assemble if symbol value is not 0. */
{ PSEUDO, "IFZERO", IFZERO }, /* Assemble if symbol value is 0. */
{ PSEUDO, "NOPUNC", NOPUNCH }, /* Turn off object code generation. */
{ PSEUDO, "OCTAL", OCTAL }, /* Read literal constants in base 8. */
{ PSEUDO, "PAGE", PAGE }, /* Set orign to page +1 or page n (0..37).*/
{ PSEUDO, "PAUSE", PAUSE }, /* Ignored */
{ PSEUDO, "RELOC", RELOC }, /* Assemble to run at a different address.*/
{ PSEUDO, "RIMPUN", RIMPUNCH }, /* Output in Read In Mode format. */
{ PSEUDO, "SEGMNT", SEGMNT }, /* Like page, but with page size=1K words.*/
{ PSEUDO, "TEXT", TEXT }, /* Pack 6 bit trimmed ASCII into memory. */
{ PSEUDO, "TITLE", TITLE }, /* Use the text string as a listing title.*/
{ PSEUDO, "XLIST", XLIST }, /* Toggle listing generation. */
{ PSEUDO, "ZBLOCK", ZBLOCK } /* Zero a block of memory. */
};
/* Symbol Table */
/* The table is put in lexical order on startup, so symbols can be */
/* inserted as desired into the initial table. */
SYM_T permanent_symbols[] =
{
/* Memory Reference Instructions */
{ MRIFIX, "AND", 00000 }, /* LOGICAL AND */
{ MRIFIX, "TAD", 01000 }, /* TWO'S COMPLEMENT ADD */
{ MRIFIX, "ISZ", 02000 }, /* INCREMENT AND SKIP IF ZERO */
{ MRIFIX, "DCA", 03000 }, /* DEPOSIT AND CLEAR ACC */
{ MRIFIX, "I", 00400 }, /* INDIRECT ADDRESSING */
{ MRIFIX, "JMP", 05000 }, /* JUMP */
{ MRIFIX, "JMS", 04000 }, /* JUMP TO SUBROUTINE */
{ MRIFIX, "Z", 00000 }, /* PAGE ZERO ADDRESS */
/* Floating Point Interpreter Instructions */
{ MRIFIX, "FEXT", 00000 }, /* FLOATING EXIT */
{ MRIFIX, "FADD", 01000 }, /* FLOATING ADD */
{ MRIFIX, "FSUB", 02000 }, /* FLOATING SUBTRACT */
{ MRIFIX, "FMPY", 03000 }, /* FLOATING MULTIPLY */
{ MRIFIX, "FDIV", 04000 }, /* FLOATING DIVIDE */
{ MRIFIX, "FGET", 05000 }, /* FLOATING GET */
{ MRIFIX, "FPUT", 06000 }, /* FLOATING PUT */
{ FIXED, "FNOR", 07000 }, /* FLOATING NORMALIZE */
{ FIXED, "FEXT", 00000 }, /* EXIT FROM FLOATING POINT INTERPRETER */
{ FIXED, "SQUARE", 00001 }, /* SQUARE C(FAC) */
{ FIXED, "SQROOT", 00002 }, /* TAKE SQUARE ROOT OF C(FAC) */
/* Group 1 Operate Microinstrcutions */
{ FIXED, "NOP", 07000 }, /* NO OPERATION */
{ FIXED, "IAC", 07001 }, /* INCREMENT AC */
{ FIXED, "RAL", 07004 }, /* ROTATE AC AND LINK LEFT ONE */
{ FIXED, "RTL", 07006 }, /* ROTATE AC AND LINK LEFT TWO */
{ FIXED, "RAR", 07010 }, /* ROTATE AC AND LINK RIGHT ONE */
{ FIXED, "RTR", 07012 }, /* ROTATE AC AND LINK RIGHT TWO */
{ FIXED, "CML", 07020 }, /* COMPLEMENT LINK */
{ FIXED, "CMA", 07040 }, /* COMPLEMEMNT AC */
{ FIXED, "CLL", 07100 }, /* CLEAR LINK */
{ FIXED, "CLA", 07200 }, /* CLEAR AC */
/* Group 2 Operate Microinstructions */
{ FIXED, "BSW", 07002 }, /* Swap bytes in AC (PDP/8e) */
{ FIXED, "HLT", 07402 }, /* HALT THE COMPUTER */
{ FIXED, "OSR", 07404 }, /* INCLUSIVE OR SR WITH AC */
{ FIXED, "SKP", 07410 }, /* SKIP UNCONDITIONALLY */
{ FIXED, "SNL", 07420 }, /* SKIP ON NON-ZERO LINK */
{ FIXED, "SZL", 07430 }, /* SKIP ON ZERO LINK */
{ FIXED, "SZA", 07440 }, /* SKIP ON ZERO AC */
{ FIXED, "SNA", 07450 }, /* SKIP ON NON=ZERO AC */
{ FIXED, "SMA", 07500 }, /* SKIP MINUS AC */
{ FIXED, "SPA", 07510 }, /* SKIP ON POSITIVE AC (ZERO IS POSITIVE) */
/* Combined Operate Microinstructions */
{ FIXED, "CIA", 07041 }, /* COMPLEMENT AND INCREMENT AC */
{ FIXED, "STL", 07120 }, /* SET LINK TO 1 */
{ FIXED, "GLK", 07204 }, /* GET LINK (PUT LINK IN AC BIT 11) */
{ FIXED, "STA", 07240 }, /* SET AC TO -1 */
{ FIXED, "LAS", 07604 }, /* LOAD ACC WITH SR */
/* MQ Instructions (PDP/8e) */
{ FIXED, "MQL", 07421 }, /* Load MQ from AC, then clear AC. */
{ FIXED, "MQA", 07501 }, /* Inclusive OR MQ with AC */
{ FIXED, "SWP", 07521 }, /* Swap AC and MQ */
{ FIXED, "ACL", 07701 }, /* Load MQ into AC */
/* Program Interrupt */
{ FIXED, "IOT", 06000 },
{ FIXED, "ION", 06001 }, /* TURN INTERRUPT PROCESSOR ON */
{ FIXED, "IOF", 06002 }, /* TURN INTERRUPT PROCESSOR OFF */
/* Program Interrupt, PDP-8/e */
{ FIXED, "SKON", 06000 }, /* Skip if interrupt on and turn int off. */
{ FIXED, "SRQ", 06003 }, /* Skip on interrupt request. */
{ FIXED, "GTF", 06004 }, /* Get interrupt flags. */
{ FIXED, "RTF", 06005 }, /* Restore interrupt flags. */
{ FIXED, "SGT", 06006 }, /* Skip on greater than flag. */
{ FIXED, "CAF", 06007 }, /* Clear all flags. */
/* Keyboard/Reader */
{ FIXED, "KSF", 06031 }, /* SKIP ON KEYBOARD FLAG */
{ FIXED, "KCC", 06032 }, /* CLEAR KEYBOARD FLAG */
{ FIXED, "KRS", 06034 }, /* READ KEYBOARD BUFFER (STATIC) */
{ FIXED, "KRB", 06036 }, /* READ KEYBOARD BUFFER & CLEAR FLAG */
/* Teleprinter/Punch */
{ FIXED, "TSF", 06041 }, /* SKIP ON TELEPRINTER FLAG */
{ FIXED, "TCF", 06042 }, /* CLEAR TELEPRINTER FLAG */
{ FIXED, "TPC", 06044 }, /* LOAD TELEPRINTER & PRINT */
{ FIXED, "TLS", 06046 }, /* LOAD TELPRINTER & CLEAR FLAG */
/* High Speed Paper Tape Reader */
{ FIXED, "RSF", 06011 }, /* SKIP ON READER FLAG */
{ FIXED, "RRB", 06012 }, /* READ READER BUFFER AND CLEAR FLAG */
{ FIXED, "RFC", 06014 }, /* READER FETCH CHARACTER */
/* PC8-E High Speed Paper Tape Reader & Punch */
{ FIXED, "RPE", 06010 }, /* Set interrupt enable for reader/punch */
{ FIXED, "PCE", 06020 }, /* Clear interrupt enable for rdr/punch */
{ FIXED, "RCC", 06016 }, /* Read reader buffer, clear flags & buf, */
/* and fetch character. */
/* High Speed Paper Tape Punch */
{ FIXED, "PSF", 06021 }, /* SKIP ON PUNCH FLAG */
{ FIXED, "PCF", 06022 }, /* CLEAR ON PUNCH FLAG */
{ FIXED, "PPC", 06024 }, /* LOAD PUNCH BUFFER AND PUNCH CHARACTER* */
{ FIXED, "PLS", 06026 }, /* LOAD PUNCH BUFFER AND CLEAR FLAG */
/* DECtape Transport Type TU55 and DECtape Control Type TC01 */
{ FIXED, "DTRA", 06761 }, /* Contents of status register is ORed */
/* into AC bits 0-9 */
{ FIXED, "DTCA", 06762 }, /* Clear status register A, all flags */
/* undisturbed */
{ FIXED, "DTXA", 06764 }, /* Status register A loaded by exclusive */
/* OR from AC. If AC bit 10=0, clear */
/* error flags; if AC bit 11=0, DECtape */
/* control flag is cleared. */
{ FIXED, "DTLA", 06766 }, /* Combination of DTCA and DTXA */
{ FIXED, "DTSF", 06771 }, /* Skip if error flag is 1 or if DECtape */
/* control flag is 1 */
{ FIXED, "DTRB", 06772 }, /* Contents of status register B is */
/* ORed into AC */
{ FIXED, "DTLB", 06774 }, /* Memory field portion of status */
/* register B loaded from AC bits 6-8 */
/* Disk File and Control, Type DF32 */
{ FIXED, "DCMA", 06601 }, /* CLEAR DISK MEMORY REQUEST AND */
/* INTERRUPT FLAGS */
{ FIXED, "DMAR", 06603 }, /* LOAD DISK FROM AC, CLEAR AC READ */
/* INTO CORE, CLEAR INTERRUPT FLAG */
{ FIXED, "DMAW", 06605 }, /* LOAD DISK FROM AC, WRITE ONTO DISK */
/* FROM CORE, CLEAR INTERRUPT FLAG */
{ FIXED, "DCEA", 06611 }, /* CLEAR DISK EXTENDED ADDRESS AND */
{ FIXED, "DSAC", 06612 }, /* SKIP IF ADDRESS CONFIRMED FLAG = 1 */
/* MEMORY ADDRESS EXTENSION REGISTER */
{ FIXED, "DEAL", 06615 }, /* CLEAR DISK EXTENDED ADDRESS AND */
/* MEMORY ADDRESS EXTENSION REGISTER */
/* AND LOAD SAME FROM AC */
{ FIXED, "DEAC", 06616 }, /* CLEAR AC, LOAD AC FROM DISK EXTENDED */
/* ADDRESS REGISTER, SKIP IF ADDRESS */
/* CONFIRMED FLAG = 1 */
{ FIXED, "DFSE", 06621 }, /* SKIP IF PARITY ERROR, DATA REQUEST */
/* LATE, OR WRITE LOCK SWITCH FLAG = 0 */
/* (NO ERROR) */
{ FIXED, "DFSC", 06622 }, /* SKIP IF COMPLETION FLAG = 1 (DATA */
/* TRANSFER COMPLETE) */
{ FIXED, "DMAC", 06626 }, /* CLEAR AC, LOAD AC FROM DISK MEMORY */
/* ADDRESS REGISTER */
/* Disk File and Control, Type RF08 */
{ FIXED, "DCIM", 06611 },
{ FIXED, "DIML", 06615 },
{ FIXED, "DIMA", 06616 },
{ FIXED, "DISK", 06623 },
{ FIXED, "DCXA", 06641 },
{ FIXED, "DXAL", 06643 },
{ FIXED, "DXAC", 06645 },
{ FIXED, "DMMT", 06646 },
/* Memory Extension Control, Type 183 */
{ FIXED, "CDF", 06201 }, /* CHANGE DATA FIELD */
{ FIXED, "CIF", 06202 }, /* CHANGE INSTRUCTION FIELD */
{ FIXED, "CDI", 06203 }, /* Change data & instrution field. */
{ FIXED, "RDF", 06214 }, /* READ DATA FIELD */
{ FIXED, "RIF", 06224 }, /* READ INSTRUCTION FIELD */
{ FIXED, "RIB", 06234 }, /* READ INTERRUPT BUFFER */
{ FIXED, "RMF", 06224 }, /* RESTORE MEMORY FIELD */
/* Memory Parity, Type MP8/I (MP8/L) */
{ FIXED, "SMP", 06101 }, /* SKIP IF MEMORY PARITY FLAG = 0 */
{ FIXED, "CMP", 06104 }, /* CLEAR MEMORY PAIRTY FLAG */
/* Memory Parity, Type MP8-E (PDP8/e) */
{ FIXED, "DPI", 06100 }, /* Disable parity interrupt. */
{ FIXED, "SNP", 06101 }, /* Skip if no parity error. */
{ FIXED, "EPI", 06103 }, /* Enable parity interrupt. */
{ FIXED, "CNP", 06104 }, /* Clear parity error flag. */
{ FIXED, "CEP", 06106 }, /* Check for even parity. */
{ FIXED, "SPO", 06107 }, /* Skip on parity option. */
/* Data Communications Systems, Type 680I */
{ FIXED, "TTINCR", 06401 }, /* The content of the line select */
/* register is incremented by one. */
{ FIXED, "TTI", 06402 }, /* The line status word is read and */
/* sampled. If the line is active for */
/* the fourth time, the line bit is */
/* shifted into the character assembly */
/* word. If the line bit is active for */
/* a number of times less than four, */
/* the count is incremented. If the */
/* line is not active, the active/inac- */
/* tive status of the line is recorded */
{ FIXED, "TTO", 06404 }, /* The character in the AC is shifted */
/* right one position, zeros are shifted */
/* into vacated positions, and the orig- */
/* inal content of AC11 is transferred */
/* out of the computer on the TTY line. */
{ FIXED, "TTCL", 06411 }, /* The line select register is cleared. */
{ FIXED, "TTSL", 06412 }, /* The line select register is loaded by */
/* an OR transfer from the content of */
/* of AC5-11, the the AC is cleared. */
{ FIXED, "TTRL", 06414 }, /* The content of the line select regis- */
/* ter is read into AC5-11 by an OR */
/* transfer. */
{ FIXED, "TTSKP", 06421 }, /* Skip if clock flag is a 1. */
{ FIXED, "TTXON", 06424 }, /* Clock 1 is enabled to request a prog- */
/* ram interrupt and clock 1 flag is */
/* cleared. */
{ FIXED, "TTXOF", 06422 }, /* Clock 1 is disabled from causing a */
/* program interrupt and clock 1 flag */
/* is cleared. */
}; /* End-of-Symbols for Permanent Symbol Table */
/* Global variables */
SYM_T *symtab; /* Symbol Table */
int symbol_top; /* Number of entries in symbol table. */
SYM_T *fixed_symbols; /* Start of the fixed symbol table entries. */
int number_of_fixed_symbols;
/*----------------------------------------------------------------------------*/
WORD16 *xreftab; /* Start of the concordance table. */
ERRSAVE_T error_list[20];
int save_error_count;
LPOOL_T pz; /* Storage for page zero constants. */
LPOOL_T cp; /* Storage for current page constants. */
char s_detected[] = "detected";
char s_error[] = "error";
char s_errors[] = "errors";
char s_no[] = "No";
char s_page[] = "Page";
char s_symtable[] = "Symbol Table";
char s_xref[] = "Cross Reference";
/* Assembler diagnostic messages. */
/* Some attempt has been made to keep continuity with the PAL-III and */
/* MACRO-8 diagnostic messages. If a diagnostic indicator, (e.g., IC) */
/* exists, then the indicator is put in the listing as the first two */
/* characters of the diagnostic message. The PAL-III indicators where used */
/* when there was a choice between using MACRO-8 and PAL-III indicators. */
/* The character pairs and their meanings are: */
/* DT Duplicate Tag (symbol) */
/* IC Illegal Character */
/* ID Illegal Redefinition of a symbol. An attempt was made to give */
/* a symbol a new value not via =. */
/* IE Illegal Equals An equal sign was used in the wrong context, */
/* (e.g., A+B=C, or TAD A+=B) */
/* II Illegal Indirect An off page reference was made, but a literal */
/* could not be generated because the indirect bit was already set. */
/* IR Illegal Reference (address is not on current page or page zero) */
/* ND No $ (the program terminator) at end of file. */
/* PE Current, Non-Zero Page Exceeded (literal table flowed into code) */
/* RD ReDefintion of a symbol */
/* ST Symbol Table full */
/* UA Undefined Address (undefined symbol) */
/* ZE Zero Page Exceeded (see above, or out of space) */
EMSG_T duplicate_label = { "DT duplicate", "duplicate label" };
EMSG_T illegal_blank = { "IC illegal blank", "illegal blank" };
EMSG_T illegal_character = { "IC illegal char", "illegal character" };
EMSG_T illegal_expression = { "IC in expression", "illegal expression" };
EMSG_T label_syntax = { "IC label syntax", "label syntax" };
EMSG_T not_a_number = { "IC numeric syntax", "numeric syntax of" };
EMSG_T number_not_radix = { "IC radix", "number not in current radix"};
EMSG_T symbol_syntax = { "IC symbol syntax", "symbol syntax" };
EMSG_T illegal_equals = { "IE illegal =", "illegal equals" };
EMSG_T illegal_indirect = { "II off page", "illegal indirect" };
EMSG_T illegal_reference = { "IR off page", "illegal reference" };
EMSG_T undefined_symbol = { "UD undefined", "undefined symbol" };
EMSG_T redefined_symbol = { "RD redefined", "redefined symbol" };
EMSG_T literal_overflow = { "PE page exceeded",
"current page literal capacity exceeded" };
EMSG_T pz_literal_overflow = { "ZE page exceeded",
"page zero capacity exceeded" };
EMSG_T dubl_overflow = { "dubl overflow", "DUBL value overflow" };
EMSG_T fltg_overflow = { "fltg overflow", "FLTG value overflow" };
EMSG_T zblock_too_small = { "expr too small", "ZBLOCK value too small" };
EMSG_T zblock_too_large = { "expr too large", "ZBLOCK value too large" };
EMSG_T end_of_file = { "ND no $ at EOF", "No $ at End-of-File" };
EMSG_T no_pseudo_op = { "not implemented",
"not implemented pseudo-op" };
EMSG_T illegal_field_value = { "expr out of range",
"field value not in range of 0 through 7" };
EMSG_T literal_gen_off = { "literals off",
"literal generation is off" };
EMSG_T no_literal_value = { "no value", "no literal value" };
EMSG_T text_string = { "no delimiter",
"text string delimiters not matched" };
EMSG_T in_rim_mode = { "not OK in rim mode"
"FIELD pseudo-op not valid in RIM mode" };
EMSG_T lt_expected = { "'<' expected", "'<' expected" };
EMSG_T symbol_table_full = { "ST Symbol Tbl Full",
"Symbol Table Full" };
/*----------------------------------------------------------------------------*/
FILE *errorfile;
FILE *infile;
FILE *listfile;
FILE *listsave;
FILE *objectfile;
FILE *objectsave;
char errorpathname[NAMELEN];
char filename[NAMELEN];
char listpathname[NAMELEN];
char objectpathname[NAMELEN];
char *pathname;
char permpathname[NAMELEN];
int list_lineno;
int list_pageno;
char list_title[LINELEN];
BOOL list_title_set; /* Set if TITLE pseudo-op used. */
char line[LINELEN]; /* Input line. */
int lineno; /* Current line number. */
int page_lineno; /* print line number on current page. */
BOOL listed; /* Listed flag. */
int cc; /* Column Counter (char position in line). */
WORD16 checksum; /* Generated checksum */
BOOL binary_data_output; /* Set true when data has been output. */
WORD16 clc; /* Location counter */
WORD16 cplc; /* Current page literal counter. */
char delimiter; /* Character immediately after eval'd term. */
int errors; /* Number of errors found so far. */
BOOL error_in_line; /* TRUE if error on current line. */
int errors_pass_1; /* Number of errors on pass 1. */
WORD16 field; /* Current field */
WORD16 fieldlc; /* location counter without field portion. */
BOOL fltg_input; /* TRUE when doing floating point input. */
BOOL indirect_generated; /* TRUE if an off page address generated. */
int last_xref_lexstart; /* Column where last xref symbol was located. */
int last_xref_lineno; /* Line where last xref symbol was located. */
int lexstartprev; /* Where previous lexeme started. */
int lextermprev; /* Where previous lexeme ended. */
int lexstart; /* Index of current lexeme on line. */
int lexterm; /* Index of character after current lexeme. */
BOOL literals_on; /* Generate literals, defaults to none */
int maxcc; /* Current line length. */
BOOL overflow; /* Overflow flag for math routines. */
int pass; /* Number of current pass. */
BOOL print_permanent_symbols;
WORD16 pzlc; /* Page Zero literal counter. */
WORD16 radix; /* Default number radix. */
WORD16 reloc; /* The relocation distance. */
BOOL rim_mode; /* Generate rim format, defaults to bin */
BOOL symtab_print; /* Print symbol table flag */
BOOL xref;
FLTG_T fltg_ac; /* Value holder for evalFltg() */
SYM_T sym_eval = { DEFINED, "", 0 }; /* Value holder for eval() */
SYM_T sym_getexpr = { DEFINED, "", 0 }; /* Value holder for getexpr() */
SYM_T sym_undefined = { UNDEFINED, "", 0 };/* Symbol Table Terminator */
/******************************************************************************/
/* */
/* Function: main */
/* */
/* Synopsis: Starting point. Controls order of assembly. */
/* */
/******************************************************************************/
int main( int argc, char *argv[] )
{
int ix;
int space;
/* Set the default values for global symbols. */
binary_data_output = FALSE;
fltg_input = FALSE;
literals_on = FALSE;
print_permanent_symbols = FALSE;
rim_mode = FALSE;
symtab_print = FALSE;
xref = FALSE;
pathname = NULL;
/* Get the options and pathnames */
getArgs( argc, argv );
/* Setup the error file in case symbol table overflows while installing the */
/* permanent symbols. */
errorfile = fopen( errorpathname, "w" );
errors = 0;
save_error_count = 0;
pass = 0; /* This is required for symbol table initialization. */
symtab = (SYM_T *) malloc( sizeof( SYM_T ) * SYMBOL_TABLE_SIZE );
if( symtab == NULL )
{
fprintf( stderr, "Could not allocate memory for symbol table.\n");
exit( -1 );
}
/* Place end marker in symbol table. */
symtab[0] = sym_undefined;
symbol_top = 0;
number_of_fixed_symbols = symbol_top;
fixed_symbols = &symtab[symbol_top - 1];
/* Enter the pseudo-ops into the symbol table */
for( ix = 0; ix < DIM( pseudo ); ix++ )
{
defineSymbol( pseudo[ix].name, pseudo[ix].val, pseudo[ix].type, 0 );
}
/* Enter the predefined symbols into the table. */
/* Also make them part of the permanent symbol table. */
for( ix = 0; ix < DIM( permanent_symbols ); ix++ )
{
defineSymbol( permanent_symbols[ix].name,
permanent_symbols[ix].val,
permanent_symbols[ix].type | DEFFIX , 0 );
}
number_of_fixed_symbols = symbol_top;
fixed_symbols = &symtab[symbol_top - 1];
/* Do pass one of the assembly */
checksum = 0;
pass = 1;
page_lineno = LIST_LINES_PER_PAGE;
onePass();
errors_pass_1 = errors;
/* Set up for pass two */
rewind( infile );
errorfile = fopen( errorpathname, "w" );
objectfile = fopen( objectpathname, "wb" );
objectsave = objectfile;
listfile = fopen( listpathname, "w" );
listsave = NULL;
punchLeader( 0 );
checksum = 0;
/* Do pass two of the assembly */
errors = 0;
save_error_count = 0;
page_lineno = LIST_LINES_PER_PAGE;
if( xref )
{
/* Get the amount of space that will be required for the concordance. */
for( space = 0, ix = 0; ix < symbol_top; ix++ )
{
symtab[ix].xref_index = space; /* Index into concordance table. */
space += symtab[ix].xref_count + 1;
symtab[ix].xref_count = 0; /* Clear the count for pass 2. */
}
/* Allocate the necessary space. */
xreftab = (WORD16 *) malloc( sizeof( WORD16 ) * space );
/* Clear the cross reference space. */
for( ix = 0; ix < space; ix++ )
{
xreftab[ix] = 0;
}
}
pass = 2;
onePass();
/* Undo effects of NOPUNCH for any following checksum */
objectfile = objectsave;
punchChecksum();
/* Works great for trailer. */
punchLeader( 1 );
/* undo effects of XLIST for any following output to listing file. */
if( listfile == NULL )
{
listfile = listsave;
}
/* Display value of error counter. */
if( errors == 0 )
{
fprintf( listfile, "\n %s %s %s\n", s_no, s_detected, s_errors );
}
else
{
fprintf( errorfile, "\n %d %s %s\n", errors, s_detected,
( errors == 1 ? s_error : s_errors ));
fprintf( listfile, "\n %d %s %s\n", errors, s_detected,
( errors == 1 ? s_error : s_errors ));
fprintf( stderr, " %d %s %s\n", errors, s_detected,
( errors == 1 ? s_error : s_errors ));
}
if( symtab_print )
{
printSymbolTable();
}
if( print_permanent_symbols )
{
printPermanentSymbolTable();
}
if( xref )
{
printCrossReference();
}
fclose( objectfile );
fclose( listfile );
fclose( errorfile );
if( errors == 0 && errors_pass_1 == 0 )
{
remove( errorpathname );
}
return( errors != 0 );
} /* main() */
/******************************************************************************/
/* */
/* Function: getArgs */
/* */
/* Synopsis: Parse command line, set flags accordingly and setup input and */
/* output files. */
/* */
/******************************************************************************/
void getArgs( int argc, char *argv[] )
{
int len;
int ix, jx;
/* Set the defaults */
errorfile = NULL;
infile = NULL;
listfile = NULL;
listsave = NULL;
objectfile = NULL;
objectsave = NULL;
for( ix = 1; ix < argc; ix++ )
{
if( argv[ix][0] == '-' )
{
for( jx = 1; argv[ix][jx] != 0; jx++ )
{
switch( argv[ix][jx] )
{
case 'd':
symtab_print = TRUE;
break;
case 'r':
rim_mode = TRUE;
break;
case 'l':
literals_on = TRUE;
break;
case 'p':
print_permanent_symbols = TRUE;
break;
case 'x':
xref = TRUE;
break;
case 'v':
fprintf( stderr, "%s\n", release );
fflush( stderr );
exit( -1 );
break;
default:
fprintf( stderr, "%s: unknown flag: %s\n", argv[0], argv[ix] );
case 'h':
fprintf( stderr, " -d -- dump symbol table\n" );
fprintf( stderr, " -h -- show this help\n" );
fprintf( stderr, " -l -- generate literals\n" );
fprintf( stderr, " -r -- output rim format file\n" );
fprintf( stderr, " -p -- output permanent symbols to file\n" );
fprintf( stderr, " -v -- display version\n" );
fprintf( stderr, " -x -- output cross reference to file\n" );
fflush( stderr );
exit( -1 );
} /* end switch */
} /* end for */
}
else
{
if( pathname != NULL )
{
fprintf( stderr, "%s: too many input files\n", argv[0] );
exit( -1 );
}
pathname = &argv[ix][0];
}
} /* end for */
if( pathname == NULL )
{
fprintf( stderr, "%s: no input file specified\n", argv[0] );
exit( -1 );
}
len = strlen( pathname );
if( len > NAMELEN - 5 )
{
fprintf( stderr, "%s: pathname \"%s\" too long\n", argv[0], pathname );
exit( -1 );
}
/* Now open the input file. */
if(( infile = fopen( pathname, "r" )) == NULL )
{
fprintf( stderr, "%s: cannot open \"%s\"\n", argv[0], pathname );
exit( -1 );
}