-
Notifications
You must be signed in to change notification settings - Fork 1
/
as1750.c
1295 lines (1226 loc) · 31.6 KB
/
as1750.c
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
/***************************************************************************/
/* */
/* Project : as1750 -- Mil-Std-1750 Assembler and Linker */
/* */
/* Component : as1750.c -- 1750 instruction assembly */
/* */
/* Copyright : (C) Daimler-Benz Aerospace AG, 1994-1997 */
/* */
/* Author : Oliver M. Kellogg, Dornier Satellite Systems, */
/* Dept. RST13, D-81663 Munich, Germany. */
/* Contact : oliver.kellogg@space.otn.dasa.de */
/* */
/* Disclaimer: */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* */
/***************************************************************************/
#ifdef AS1750
#include "common.h"
#include "utils.h"
#else /* ASL */
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include "datatypes.h"
#include "strutil.h"
#include "asmdef.h"
#include "asmsub.h"
#include "asmpars.h"
#include "as1750.h"
#define bool char
#define ushort unsigned short
#define ulong unsigned long
#define status unsigned
#define dtoi(ascii_char) (ascii_char - '0')
#endif
#ifndef AS1750
static
#endif
status /* Output an error text (printf style). */
error (char *layout,...) /* Return the ERROR status code. */
{
va_list vargu;
char output_line[132];
va_start (vargu, layout);
vsprintf (output_line, layout, vargu);
#ifdef AS1750
fprintf (stderr, "%s line%5d: %s\n", nopath (file[curr_file].name),
file[curr_file].line_number, output_line);
#else /* ASL */
WrErrorString (output_line, "\0", 0, 0);
#endif
va_end (vargu);
return ERROR;
}
/* Get a number. Return pointer to first position in s after the end of
* the number, or NULL for error.
* Will also read character constants of the form: 'x', and two-character
* packed strings of the form "xy" (where x=>highbyte,y=>lowbyte.)
*/
#ifdef AS1750
char *
get_num (char *s, int *outnum)
{
bool is_neg = FALSE, intel = FALSE, c_lang = FALSE, tld = FALSE;
char *start;
*outnum = 0;
if (*s == '-')
{
is_neg = TRUE;
++s;
}
else if (*s == '+')
++s;
/* determine if Intel format */
if (isdigit (*s))
{
char *p = s;
while (isxdigit (*++p))
;
if (upcase (*p) == 'H')
intel = TRUE;
}
if (intel
|| (c_lang = (*s == '0' && upcase (*(s + 1)) == 'X'))
|| (tld = strncmp (s, "16#", 3) == 0))
{
s += c_lang ? 2 : tld ? 3 : 0;
start = s;
while (isxdigit (*s))
{
*outnum = (*outnum << 4) | xtoi (*s);
++s;
}
if (s - start > 4)
{
error ("get_num -- number at '%s' too large", start);
return NULL;
}
if (intel)
s++;
else if (tld)
{
if (*s != '#')
{
error ("get_num -- expecting '#' at end of number");
return NULL;
}
s++;
}
}
else if (*s == '0' || (tld = (*s == '8' && *(s + 1) == '#')))
{
s += tld ? 2 : 1;
start = s;
while (*s >= '0' && *s <= '7')
{
*outnum = (*outnum << 3) | (*s - '0');
++s;
}
if (s - start > 6)
{
error ("get_num -- number at '%s' too large", start);
return NULL;
}
if (tld)
{
if (*s != '#')
{
error ("get_num -- expecting '#' at end of number");
return NULL;
}
++s;
}
}
else if (*s == '@' || (tld = (*s == '2' && *(s + 1) == '#')))
{
s += (tld ? 2 : 1);
start = s;
while (*s == '0' || *s == '1')
{
*outnum = (*outnum << 1) | (*s - '0');
++s;
}
if (s - start > 16)
{
error ("get_num -- number at '%s' too large", start);
return NULL;
}
if (tld)
{
if (*s != '#')
{
error ("get_num -- expecting '#' at end of number");
return NULL;
}
++s;
}
}
else if (isdigit (*s))
{
start = s;
while (isdigit (*s))
{
*outnum = (*outnum * 10) + dtoi (*s);
++s;
}
if (s - start > 5)
{
error ("get_num -- number at '%s' too large", start);
return NULL;
}
}
else if (*s == '\'')
{
start = s;
if (*++s == '\\')
{
switch (*++s)
{
case 't':
*outnum = 9;
break;
case 'n':
*outnum = 10;
break;
case 'r':
*outnum = 13;
break;
default:
error ("get_num -- unknown escape '\\%c'", *s);
return NULL;
}
}
else
*outnum = (int) *s & 0xFF;
if (*++s != '\'')
{
error ("get_num -- character constant incorrectly terminated", start);
return NULL;
}
++s;
}
else if (*s == '"')
{
start = s;
*outnum = ((int) *++s & 0xFF) << 8;
*outnum |= (int) *++s & 0xFF;
if (*++s != '"')
{
error ("get_num -- character tuple incorrectly terminated", start);
return NULL;
}
++s;
}
else
return NULL;
if (is_neg)
*outnum = -*outnum;
return s;
}
/* Get a constant symbol (previously defined by EQU) or a number.
* Return pointer to first character after the symbol or number consumed,
* or NULL if reading the symbol or number was unsuccessful.
*/
char *
get_sym_num (char *s, int *outnum)
{
char *p, c;
symbol_t sym;
if ((p = get_num (s, outnum)) != NULL)
return p;
/* Didn't find a raw number; try symbol. */
if (!issymstart (*s))
{
error ("expecting symbol at '%s'", s);
return NULL;
}
p = s;
while (issymchar (*p))
p++;
c = *p;
*p = '\0';
if ((sym = find_symbol (s)) == SNULL)
{
error ("unidentified symbol at '%s'", s);
return NULL;
}
*p = c;
if (!sym->is_constant)
{
error ("symbol must be constant in this context");
return NULL;
}
*outnum = (int) sym->value;
return p;
}
extern int curr_frag; /* imported from main.c */
/* Enter a 16-bit word into the object space */
void
add_word (ushort word)
{
struct objblock *obj = &objblk[curr_frag];
if (obj->data == (ushort *) 0)
{
obj->n_allocated = 256;
obj->data = (ushort *) malloc (obj->n_allocated * sizeof (ushort));
obj->line = (struct linelist **) malloc
(obj->n_allocated * sizeof (struct linelist *));
}
else if (obj->n_used == obj->n_allocated)
{
obj->n_allocated *= 2;
obj->data = (ushort *) realloc (obj->data,
obj->n_allocated * sizeof (ushort));
obj->line = (struct linelist **) realloc (obj->line,
obj->n_allocated * sizeof (struct linelist *));
}
if (obj->data == (ushort *) 0 || obj->line == (struct linelist **) 0)
problem ("request for object space refused by OS");
obj->data[obj->n_used] = word;
obj->line[obj->n_used] = line;
obj->n_used++;
}
void
add_reloc (symbol_t sym) /* auxiliary to parse_addr() */
{
struct reloc *rel;
if (relblk.data == (struct reloc *) 0)
{
relblk.n_allocated = 256;
relblk.data = (struct reloc *) malloc
(relblk.n_allocated * sizeof (struct reloc));
}
else if (relblk.n_used == relblk.n_allocated)
{
relblk.n_allocated *= 2;
relblk.data = (struct reloc *) realloc (relblk.data,
relblk.n_allocated * sizeof (struct reloc));
}
if (relblk.data == (struct reloc *) 0)
problem ("request for relocation space refused by OS");
rel = &relblk.data[relblk.n_used];
rel->done = FALSE; /* default initializations */
rel->reltype = Word_Reloc;
rel->frag_index = curr_frag;
rel->obj_index = objblk[curr_frag].n_used;
rel->sym = sym;
relblk.n_used++;
}
/* Parse the address expression at s into object space.
Returns OKAY or ERROR. */
status
parse_addr (char *s)
{
int num;
char *p, c, c1;
symbol_t sym, sym1;
if (issymstart (*s))
{
p = skip_symbol (s);
c = *p; /* prepare for symbol lookup */
*p = '\0';
if ((sym = find_or_enter (s)) == SNULL)
return ERROR;
sym->is_referenced = TRUE;
*p = c;
s = p++;
if (c == '\0')
{
if (sym->is_constant)
add_word ((ushort) sym->value);
else
{
add_reloc (sym);
add_word (0);
}
}
else if (c != '+' && c != '-')
return error ("error after symbolname at: %s", s);
else if (issymstart (*p))
{
s = skip_symbol (p);
if (*s != '\0' && *s != ',')
return error ("address expression too complex");
c1 = *s; /* prepare for symbol lookup */
*s = '\0';
if ((sym1 = find_or_enter (p)) == SNULL)
return ERROR;
sym1->is_referenced = TRUE;
*s = c1;
if (c == '+')
{
if (sym->is_constant)
{
if (sym1->is_constant)
{
long sum = sym->value + sym1->value;
if (sum < -0x8000L)
return error ("negative overflow in symbol addition");
else if (sum > 0xFFFFL)
return error ("positive overflow in symbol addition");
add_word ((ushort) sum);
}
else
{
add_reloc (sym1);
add_word ((ushort) sym->value);
}
}
else
{
if (sym1->is_constant)
{
add_reloc (sym);
add_word ((ushort) sym1->value);
}
else
return error ("cannot add relocatable symbols");
}
}
else
/* subtraction */
{
if (sym->is_constant)
{
if (sym1->is_constant)
{
long dif = sym->value - sym1->value;
if (dif < -0x8000L)
return error ("negative overflow in symbol subtraction");
else if (dif > 0xFFFFL)
return error ("positive overflow symbol subtraction");
add_word ((ushort) dif);
}
else
error ("cannot subtract relocatable symbol from constant symbol");
}
else
{
if (sym1->is_constant)
{
add_reloc (sym);
add_word ((ushort) - sym1->value);
}
else
{
if (objblk[sym->frag_index].section !=
objblk[sym1->frag_index].section)
return error
("cannot subtract relocatable symbols from different fragments");
if (sym->value < sym1->value)
error ("warning: strange subtraction of relocatable symbols");
add_word ((ushort) (sym->value - sym1->value));
}
}
}
}
else
{
if (get_num (s, &num) == NULL)
return ERROR;
if (sym->is_constant)
{
long sum = sym->value + (long) num;
if (sum < -32768L)
return error ("neg. overflow in symbolic expression");
else if (sum > 65535L)
return error ("overflow in symbolic expression");
add_word ((ushort) sum);
}
else
{
add_reloc (sym);
add_word ((ushort) num);
}
}
}
else if ((s = get_num (s, &num)) == NULL)
return ERROR;
else
{
if (*s == '\0')
add_word ((ushort) num);
else if (*s != '+')
return error ("expected '+' in address expression at: %s", s);
else
{
++s;
if (!issymstart (*s))
return error ("expected symbolname in address expression at: %s", s);
p = skip_symbol (s);
if (*p != '\0' && *p != ',')
return error ("illegal characters after symbolname at: %s", s);
c = *p; /* prepare for symbol lookup */
*p = '\0';
if ((sym = find_or_enter (s)) == SNULL)
return ERROR;
sym->is_referenced = TRUE;
*p = c;
s = p;
if (sym->is_constant)
add_word ((ushort) (sym->value + (long) num));
else
{
add_reloc (sym);
add_word ((ushort) num);
}
}
}
return OKAY;
}
#else /* ASL */
static char *
get_sym_num (char *s, int *outnum)
{
Boolean okay;
*outnum = (int) EvalIntExpression (s, Int16, &okay);
if (!okay)
return NULL;
return (s + strlen (s)); /* Any non-NULL value will do here. */
}
#define add_word(word) WAsmCode[CodeLen++]=word
static status
parse_addr (char *s)
{
int value;
Boolean okay;
value = (int) EvalIntExpression (s, Int16, &okay);
if (!okay)
return ERROR;
add_word ((ushort) value);
return OKAY;
}
#endif /* from #else of #ifdef AS1750 */
/* From here on, everything is identical between as1750 and ASL. */
static ushort
get_num_bounded (char *s, int lowlim, int highlim)
{
int num;
if (get_sym_num (s, &num) == NULL)
return ERROR;
if (num < lowlim || num > highlim)
return error ("number not in range %d..%d", lowlim, highlim);
return (ushort) num;
}
static ushort
get_regnum (char *s)
{
ushort regnum;
*s = toupper (*s);
if (*s != 'R')
return error ("expecting register at '%s'", s);
++s;
if (!isdigit (*s))
return error ("expecting register at '%s'", s);
regnum = dtoi (*s);
++s;
if (isdigit (*s))
{
regnum = regnum * 10 + dtoi (*s);
if (regnum > 15)
return error ("register number out of range");
++s;
}
return regnum;
}
/**********************************************************************/
/* Functions to process opcode arguments according to addressing mode */
static int n_args;
static char *arg[4];
static status
check_indexreg (void)
{
if (n_args > 2)
{
ushort rx;
if ((rx = get_regnum (arg[2])) == ERROR)
return ERROR;
if (rx == 0)
return error ("R0 not an index register");
#ifdef AS1750
objblk[curr_frag].data[objblk[curr_frag].n_used - 2] |= rx;
#else /* ASL */
WAsmCode[0] |= rx;
#endif
}
return OKAY;
}
static ushort
as_r (ushort oc)
{
ushort ra, rb;
if (n_args != 2)
return error ("incorrect number of operands");
if ((ra = get_regnum (arg[0])) == ERROR)
return ERROR;
if ((rb = get_regnum (arg[1])) == ERROR)
return ERROR;
add_word (oc | (ra << 4) | rb);
return 1;
}
static ushort
as_mem (ushort oc)
{
ushort ra;
if (n_args < 2)
return error ("insufficient number of operands");
if ((ra = get_regnum (arg[0])) == ERROR)
return ERROR;
add_word (oc | (ra << 4));
if (parse_addr (arg[1]))
return ERROR;
if (check_indexreg ())
return ERROR;
return 2;
}
static ushort
as_addr (ushort oc) /* LST and LSTI */
{
if (n_args < 1)
return error ("insufficient number of operands");
add_word (oc);
if (parse_addr (arg[0]))
return ERROR;
n_args++; /* cheat check_indexreg() */
arg[2] = arg[1];
if (check_indexreg ())
return ERROR;
return 2;
}
static ushort
as_xmem (ushort oc) /* MIL-STD-1750B extended mem. addr. */
{
ushort ra;
if (n_args < 2)
return error ("insufficient number of operands");
if ((ra = get_regnum (arg[0])) == ERROR)
return ERROR;
add_word (oc | (ra << 4));
if (parse_addr (arg[1]))
return ERROR;
if (n_args > 2)
{
ushort rx;
if ((rx = get_regnum (arg[2])) == ERROR)
return ERROR;
#ifdef AS1750
objblk[curr_frag].data[objblk[curr_frag].n_used - 2] |= rx;
#else /* ASL */
WAsmCode[0] |= rx;
#endif
}
return 2;
}
static ushort
as_im_0_15 (ushort oc) /* for STC, LM, TB,SB,RB,TSB */
{
ushort ra;
if (n_args < 2)
return error ("insufficient number of operands");
if ((ra = get_num_bounded (arg[0], 0, 15)) == ERROR)
return ERROR;
add_word (oc | (ra << 4));
if (parse_addr (arg[1]))
return ERROR;
if (check_indexreg ())
return ERROR;
return 2;
}
static ushort
as_im_1_16 (ushort oc)
{
ushort ra;
if (n_args < 2)
return error ("insufficient number of operands");
if ((ra = get_num_bounded (arg[0], 1, 16)) == ERROR)
return ERROR;
add_word (oc | ((ra - 1) << 4));
if (parse_addr (arg[1]))
return ERROR;
if (check_indexreg ())
return ERROR;
return 2;
}
static ushort
as_im_ocx (ushort oc)
{
ushort ra;
if (n_args != 2)
return error ("incorrect number of operands");
if ((ra = get_regnum (arg[0])) == ERROR)
return ERROR;
add_word (oc | (ra << 4)); /* oc has OCX in LSnibble */
if (parse_addr (arg[1]))
return ERROR;
return 2;
}
static ushort
as_is (ushort oc)
{
ushort ra, i;
if (n_args != 2)
return error ("incorrect number of operands");
if ((ra = get_regnum (arg[0])) == ERROR)
return ERROR;
if ((i = get_num_bounded (arg[1], 1, 16)) == ERROR)
return ERROR;
add_word (oc | (ra << 4) | (i - 1));
return 1;
}
static ushort
as_icr (ushort oc)
{
#ifdef AS1750
struct objblock *obj = &objblk[curr_frag];
int last = obj->n_used;
#endif
if (n_args != 1)
return error ("incorrect number of operands");
if (parse_addr (arg[0]))
return ERROR;
#ifdef AS1750
/* If symbol relocation, then set the relocation type to Byte_Reloc */
if (relblk.n_used > 0)
{
struct reloc *rel = &relblk.data[relblk.n_used - 1];
if (rel->frag_index == curr_frag && rel->obj_index == last)
rel->reltype = Byte_Reloc;
}
obj->data[last] &= 0x00FF;
obj->data[last] |= oc;
#else /* ASL */
{
const short target = (short) WAsmCode[0];
const long curr_pc = (long) EProgCounter () & 0xFFFFL;
const long diff = (long) target - curr_pc;
if (diff < -128L || diff > 127L)
return error
("address distance too large in Instruction Counter Relative operation");
WAsmCode[0] = oc | (ushort) (diff & 0xFFL);
}
#endif
return 1;
}
static ushort
as_b (ushort oc)
{
char r;
ushort br, lobyte;
if (n_args != 2)
return error ("incorrect number of operands");
r = toupper (*arg[0]);
if (r != 'B' && r != 'R')
return error ("expecting base register");
if ((br = get_num_bounded (arg[0] + 1, 12, 15)) == ERROR)
return ERROR;
if ((lobyte = get_num_bounded (arg[1], 0, 255)) == ERROR)
return ERROR;
add_word (oc | ((br - 12) << 8) | lobyte);
return 1;
}
static ushort
as_bx (ushort oc)
{
char r;
ushort br, rx = 0;
if (n_args != 2)
return error ("incorrect number of operands");
r = toupper (*arg[0]);
if ((r != 'B' && r != 'R')
|| (br = get_num_bounded (arg[0] + 1, 12, 15)) == ERROR)
return error ("expecting base register");
if ((rx = get_regnum (arg[1])) == ERROR)
return ERROR;
if (rx == 0)
return error ("R0 not an index register");
add_word (oc | ((br - 12) << 8) | rx);
return 1;
}
static ushort
as_r_imm (ushort oc) /* for shifts with immediate shiftcount */
{
ushort rb, n;
if (n_args != 2)
return error ("incorrect number of operands");
if ((rb = get_regnum (arg[0])) == ERROR)
return ERROR;
if ((n = get_num_bounded (arg[1], 1, 16)) == ERROR)
return ERROR;
add_word (oc | ((n - 1) << 4) | rb);
return 1;
}
static ushort
as_imm_r (ushort oc) /* for test/set/reset-bit in reg. */
{
ushort n, rb;
if (n_args != 2)
return error ("incorrect number of operands");
if ((n = get_num_bounded (arg[0], 0, 15)) == ERROR)
return ERROR;
if ((rb = get_regnum (arg[1])) == ERROR)
return ERROR;
add_word (oc | (n << 4) | rb);
return 1;
}
static ushort
as_jump (ushort oc)
{
ushort condcode = 0xFFFF;
static const struct
{
char *name;
ushort value;
}
cond[] =
{ /* CPZN */
{ "LT", 0x1 }, /* 0001 */
{ "LZ", 0x1 }, /* 0001 */
{ "EQ", 0x2 }, /* 0010 */
{ "EZ", 0x2 }, /* 0010 */
{ "LE", 0x3 }, /* 0011 */
{ "LEZ", 0x3 }, /* 0011 */
{ "GT", 0x4 }, /* 0100 */
{ "GTZ", 0x4 }, /* 0100 */
{ "NE", 0x5 }, /* 0101 */
{ "NZ", 0x5 }, /* 0101 */
{ "GE", 0x6 }, /* 0110 */
{ "GEZ", 0x6 }, /* 0110 */
{ "ALL", 0x7 }, /* 0111 */
{ "CY", 0x8 }, /* 1000 */
{ "CLT", 0x9 }, /* 1001 */
{ "CEQ", 0xA }, /* 1010 */
{ "CEZ", 0xA }, /* 1010 */
{ "CLE", 0xB }, /* 1011 */
{ "CGT", 0xC }, /* 1100 */
{ "CNZ", 0xD }, /* 1101 */
{ "CGE", 0xE }, /* 1110 */
{ "UC", 0xF } /* 1111 */
};
if (n_args < 2)
return error ("insufficient number of operands");
if (isalpha (*arg[0]))
{
int i;
for (i = 0; i < 22; i++)
if (!strcasecmp (arg[0], cond[i].name))
{
condcode = cond[i].value;
break;
}
}
if (condcode == 0xFFFF)
if ((condcode = get_num_bounded (arg[0], 0, 15)) == ERROR)
return ERROR;
add_word (oc | (condcode << 4));
if (parse_addr (arg[1]))
return ERROR;
if (check_indexreg ())
return ERROR;
return 2;
}
static ushort
as_s (ushort oc) /* For the moment, BEX only. */
{
ushort lsnibble;
if (n_args != 1)
return error ("incorrect number of operands");
if ((lsnibble = get_num_bounded (arg[0], 0, 15)) == ERROR)
return ERROR;
add_word (oc | lsnibble);
return 1;
}
static ushort
as_sr (ushort oc) /* XBR and URS. */
{
ushort hlp;
if (n_args != 1)
return error ("incorrect number of operands");
if ((hlp = get_regnum (arg[0])) == ERROR)
return ERROR;
add_word (oc | (hlp << 4));
return 1;
}
static ushort
as_xio (ushort oc)
{
ushort ra;
int cmdfld = -1;
static const struct
{
char *mnem;
ushort cmd;
}
xio[] =
{
{ "SMK", 0x2000 },
{ "CLIR", 0x2001 },
{ "ENBL", 0x2002 },
{ "DSBL", 0x2003 },
{ "RPI", 0x2004 },
{ "SPI", 0x2005 },
{ "OD", 0x2008 },
{ "RNS", 0x200A },
{ "WSW", 0x200E },
{ "CO", 0x4000 },
{ "CLC", 0x4001 },
{ "MPEN", 0x4003 },
{ "ESUR", 0x4004 },
{ "DSUR", 0x4005 },
{ "DMAE", 0x4006 },
{ "DMAD", 0x4007 },
{ "TAS", 0x4008 },
{ "TAH", 0x4009 },
{ "OTA", 0x400A },
{ "GO", 0x400B },
{ "TBS", 0x400C },
{ "TBH", 0x400D },
{ "OTB", 0x400E },
{ "LMP", 0x5000 },
{ "WIPR", 0x5100 },
{ "WOPR", 0x5200 },
{ "RMP", 0xD000 },
{ "RIPR", 0xD100 },
{ "ROPR", 0xD200 },
{ "RMK", 0xA000 },
{ "RIC1", 0xA001 },
{ "RIC2", 0xA002 },
{ "RPIR", 0xA004 },
{ "RDOR", 0xA008 },
{ "RDI", 0xA009 },
{ "TPIO", 0xA00B },
{ "RMFS", 0xA00D },
{ "RSW", 0xA00E },
{ "RCFR", 0xA00F },
{ "CI", 0xC000 },
{ "RCS", 0xC001 },
{ "ITA", 0xC00A },
{ "ITB", 0xC00E },
{ "", 0xFFFF }
};
if (n_args < 2)
return error ("incorrect number of operands");
if ((ra = get_regnum (arg[0])) == ERROR)
return ERROR;
add_word (oc | (ra << 4));
/* Get the XIO command field. */
if (isalpha (*arg[1]))
{
int i;
for (i = 0; xio[i].cmd != 0xFFFF; i++)
if (!strcasecmp (arg[1], xio[i].mnem))
break;
if (xio[i].cmd != 0xFFFF)
cmdfld = xio[i].cmd;
}
if (cmdfld == -1)
if (get_sym_num (arg[1], &cmdfld) == NULL)
return ERROR;
add_word ((ushort) cmdfld);
if (check_indexreg ())
return ERROR;
return 2;
}
static ushort
as_none (ushort oc)
{
add_word (oc);
return 1;
}