OpenCores
URL https://opencores.org/ocsvn/tms1000/tms1000/trunk

Subversion Repositories tms1000

[/] [tms1000/] [trunk/] [assembler/] [casmy.y] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 nand_gates
/*
2
casm.y: grammar
3
 
4
CASM is an assembler for the TMS1000 processor.
5
*/
6
 
7
%{
8
#include 
9
#include "symtab.h"
10
#include "casm.h"
11
int bitreverse4[]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
12
int bitreverse2[]={0,2,1,3};
13
%}
14
 
15
%union {
16
    int integer;
17
    char *string;
18
  }
19
 
20
 
21
%token  INTEGER
22
%token  IDENT
23
 
24
%token  BR
25
%token  CALL
26
%token  CALLL
27
%token  CLO
28
%token  COMX
29
%token  LDP
30
%token  LDX
31
%token  SBIT
32
%token  RBIT
33
%token  RETN
34
%token  RSTR
35
%token  SETR
36
%token  TDO
37
%token  ALEC
38
%token  ALEM
39
%token  AMAAC
40
%token  A6AAC
41
%token  A8AAC
42
%token  A10AAC
43
%token  CLA
44
%token  CPAIZ
45
%token  DAN
46
%token  DMAN
47
%token  DYN
48
%token  IA
49
%token  IMAC
50
%token  IYC
51
%token  KNEZ
52
%token  MNEZ
53
%token  SAMAN
54
%token  TAM
55
%token  TAMIY
56
%token  TAMZA
57
%token  TAY
58
%token  TBIT1
59
%token  TCY
60
%token  TCMIY
61
%token  TKA
62
%token  TMA
63
%token  TMY
64
%token  TYA
65
%token  XMA
66
%token  YNEA
67
%token  YNEC
68
%token  BL
69
%token  ROM
70
%token  SYMTAB
71
 
72
%type  expr
73
 
74
%%
75
 
76
line            :       label instruction
77
                |       label
78
                |       instruction
79
                |       pseudo_op
80
                |
81
                |       error
82
                ;
83
 
84
label:          IDENT ':'       { do_label ($1); }
85
                ;
86
 
87
expr            : INTEGER { $$ = $1; }
88
                | IDENT { if (pass == 1)
89
                            $$ = 0;
90
                          else if (! lookup_symbol (symtab, $1, &$$))
91
                            {
92
                              error ("undefined symbol '%s'\n", $1);
93
                              $$ = 0;
94
                            }
95
                        }
96
                ;
97
pseudo_op       : ps_rom
98
                | ps_symtab
99
                ;
100
 
101
ps_rom          : '.' ROM expr { /*$3 = range ($3, 0, MAXGROUP * MAXROM - 1);
102
                                 group = dsg = ($3 >> 3);
103
                                 rom = dsr = ($3 & 7); */
104
                                 rom = $3;
105
                                 pc = 0;
106
                                 last_instruction_type = OTHER_INST;
107
                                 printf (" %d", $3); }
108
                ;
109
 
110
ps_symtab       : '.' SYMTAB { symtab_flag = 1; }
111
                ;
112
 
113
instruction     : inst_br
114
                | inst_bl
115
                | inst_call
116
                | inst_calll
117
                | inst_clo
118
                | inst_comx
119
                | inst_ldp
120
                | inst_ldx
121
                | inst_sbit
122
                | inst_rbit
123
                | inst_retn
124
                | inst_rstr
125
                | inst_setr
126
                | inst_tdo
127
                | inst_alec
128
                | inst_alem
129
                | inst_amaac
130
                | inst_a6aac
131
                | inst_a8aac
132
                | inst_a10aac
133
                | inst_cla
134
                | inst_cpaiz
135
                | inst_dan
136
                | inst_dman
137
                | inst_dyn
138
                | inst_ia
139
                | inst_imac
140
                | inst_iyc
141
                | inst_knez
142
                | inst_mnez
143
                | inst_saman
144
                | inst_tam
145
                | inst_tamiy
146
                | inst_tamza
147
                | inst_tay
148
                | inst_tbit1
149
                | inst_tcy
150
                | inst_tcmiy
151
                | inst_tka
152
                | inst_tma
153
                | inst_tmy
154
                | inst_tya
155
                | inst_xma
156
                | inst_ynea
157
                | inst_ynec
158
                ;
159
 
160
inst_br         : BR expr                   { emit (0x80 | ($2 & 0x3f)); } ;
161
inst_bl         : BL expr                   { emit (0x10 | bitreverse4[(($2 & 0x3c0) >> 6)]);
162
                                              pc = ((pc != 31) && ((pc >> 4) != 0) && (((pc & 0xf) == 15) || ((pc >> 4) != 3))) ?  (pc << 1) : (pc << 1)+1;
163
                                              pc = pc & 0x3f;
164
                                              emit (0x80 | ($2 & 0x3f)); } ;
165
inst_call       : CALL expr                 { emit (0xc0 | ($2 & 0x3f)); } ;
166
inst_calll      : CALLL expr                { emit (0x10 | bitreverse4[(($2 & 0x3c0) >> 6)]);
167
                                              pc = ((pc != 31) && ((pc >> 4) != 0) && (((pc & 0xf) == 15) || ((pc >> 4) != 3))) ?  (pc << 1) : (pc << 1)+1;
168
                                              pc = pc & 0x3f;
169
                                              emit (0xc0 | ($2 & 0x3f)); } ;
170
inst_clo        : CLO                       { emit (0x0b); } ;
171
inst_comx       : COMX                      { emit (0x00); } ;
172
inst_ldp        : LDP expr                  { emit (0x10 | bitreverse4[($2 & 0xf)]); } ;
173
inst_ldx        : LDX expr                  { emit (0x3c | bitreverse2[($2 & 0x3)]); } ;
174
inst_sbit       : SBIT expr                 { emit (0x30 | bitreverse2[($2 & 0x3)]); } ;
175
inst_rbit       : RBIT expr                 { emit (0x34 | bitreverse2[($2 & 0x3)]); } ;
176
inst_retn       : RETN                      { emit (0x0f); } ;
177
inst_rstr       : RSTR                      { emit (0x0c); } ;
178
inst_setr       : SETR                      { emit (0x0d); } ;
179
inst_tdo        : TDO                       { emit (0x0a); } ;
180
inst_alec       : ALEC expr                 { emit (0x70 | bitreverse4[($2 & 0xf)]); } ;
181
inst_alem       : ALEM                      { emit (0x29); } ;
182
inst_amaac      : AMAAC                     { emit (0x25); } ;
183
inst_a6aac      : A6AAC                     { emit (0x06); } ;
184
inst_a8aac      : A8AAC                     { emit (0x01); } ;
185
inst_a10aac     : A10AAC                    { emit (0x05); } ;
186
inst_cla        : CLA                       { emit (0x2f); } ;
187
inst_cpaiz      : CPAIZ                     { emit (0x2d); } ;
188
inst_dan        : DAN                       { emit (0x07); } ;
189
inst_dman       : DMAN                      { emit (0x2a); } ;
190
inst_dyn        : DYN                       { emit (0x2c); } ;
191
inst_ia         : IA                        { emit (0x0e); } ;
192
inst_imac       : IMAC                      { emit (0x28); } ;
193
inst_iyc        : IYC                       { emit (0x2b); } ;
194
inst_knez       : KNEZ                      { emit (0x09); } ;
195
inst_mnez       : MNEZ                      { emit (0x26); } ;
196
inst_saman      : SAMAN                     { emit (0x27); } ;
197
inst_tam        : TAM                       { emit (0x03); } ;
198
inst_tamiy      : TAMIY                     { emit (0x20); } ;
199
inst_tamza      : TAMZA                     { emit (0x04); } ;
200
inst_tay        : TAY                       { emit (0x24); } ;
201
inst_tbit1      : TBIT1 expr                { emit (0x38 | bitreverse2[($2 & 0x3)]); } ;
202
inst_tcy        : TCY   expr                { emit (0x40 | bitreverse4[($2 & 0xf)]); } ;
203
inst_tcmiy      : TCMIY expr                { emit (0x60 | bitreverse4[($2 & 0xf)]); } ;
204
inst_tka        : TKA                       { emit (0x08); } ;
205
inst_tma        : TMA                       { emit (0x21); } ;
206
inst_tmy        : TMY                       { emit (0x22); } ;
207
inst_tya        : TYA                       { emit (0x23); } ;
208
inst_xma        : XMA                       { emit (0x2e); } ;
209
inst_ynea       : YNEA                      { emit (0x02); } ;
210
inst_ynec       : YNEC  expr                { emit (0x50 | bitreverse4[($2 & 0xf)]); } ;
211
%%

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.