#include <setjmp.h>
#include <stdio.h>
#define NOPE
#include "as31.h"
#undef NOPE
#define YYSTYPE union ystack
extern int lineno;
extern int dashl;
extern char *asmfile;
extern jmp_buf main_env;
extern FILE *listing;
int pass, fatal;
long lc;
static unsigned char bytebuf[1024]; /* used by dumplist() */
static int bytecount;
/* ------------------------ G R A M M E R ----------------------------- */
# define STRING 257
# define D_ORG 258
# define D_BYTE 259
# define D_WORD 260
# define D_SKIP 261
# define D_EQU 262
# define D_FLAG 263
# define D_END 264
# define ACALL 265
# define ADD 266
# define ADDC 267
# define AJMP 268
# define ANL 269
# define CJNE 270
# define CLR 271
# define CPL 272
# define DA 273
# define DEC 274
# define DIV 275
# define DJNZ 276
# define INC 277
# define JB 278
# define JBC 279
# define JC 280
# define JMP 281
# define JNB 282
# define JNC 283
# define JNZ 284
# define JZ 285
# define LCALL 286
# define LJMP 287
# define MOV 288
# define MOVC 289
# define MOVX 290
# define NOP 291
# define MUL 292
# define ORL 293
# define POP 294
# define PUSH 295
# define RET 296
# define RETI 297
# define RL 298
# define RLC 299
# define RR 300
# define RRC 301
# define SETB 302
# define SJMP 303
# define SUBB 304
# define SWAP 305
# define XCH 306
# define XCHD 307
# define XRL 308
# define AB 309
# define A 310
# define C 311
# define PC 312
# define DPTR 313
# define BITPOS 314
# define R0 315
# define R1 316
# define R2 317
# define R3 318
# define R4 319
# define R5 320
# define R6 321
# define R7 322
# define VALUE 323
# define SYMBOL 324
#define yyclearin yychar = -1
#define yyerrok yyerrflag = 0
extern int yychar;
extern int yyerrflag;
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 150
#endif
#ifndef YYSTYPE
#define YYSTYPE int
#endif
YYSTYPE yylval, yyval;
typedef int yytabelem;
# define YYERRCODE 256
# line 932 "as31.y"
/* ---------------------------------------------------------------------- */
/*
* error:
* Uses semi-variable arguments. This causes immediate assembler
* termination.
*/
void error(cs, a1, a2, a3, a4, a5, a6)
char *cs, *a1, *a2, *a3, *a4, *a5, *a6;
{
fprintf(stderr, "File: %s, line: %d, ", asmfile, lineno);
fprintf(stderr, cs, a1, a2, a3, a4, a5, a6);
fprintf(stderr, ".\n");
longjmp(main_env, 1);
}
void yyerror(s)
char *s;
{
error(s);
}
/*
* warning:
* Produce error message. This will abort assembly at
* the end of the current pass.
*
*/
void warning(cs, a1, a2, a3, a4, a5, a6)
char *cs, *a1, *a2, *a3, *a4, *a5, *a6;
{
fatal++;
fprintf(stderr, "File: %s, line: %d, ", asmfile, lineno);
fprintf(stderr, cs, a1, a2, a3, a4, a5, a6);
fprintf(stderr, ".\n");
}
/* ----------------------------------------------------------------------
* inclc:
* Increments the Location Counter by 'i' amount.
* Check to see if 'i' overflows 64K.
* Checks to see if assembler is overlapping previous sections
* of code. (using a large bit field).
*/
#define indx(a) ( (a)/(sizeof(long)*8) )
#define bit(a) ( 1 << ((a)%(sizeof(long)*8)) )
#define getloc(a) (regions[indx(a)] & bit(a))
#define setloc(a) (regions[indx(a)] |= bit(a))
void inclc(i)
{
static long regions[0x10000 / (sizeof(long) * 8)];
while(i-- > 0) {
if (pass2 && getloc(lc))
error("Location counter overlaps");
if (pass2)
setloc(lc);
lc += 1;
}
if (lc > 0xffff)
error("Location counter has exceeded 16-bits");
}
/* ----------------------------------------------------------------------
* padline:
* This routine returns a new string, which is equivilant to
* 'line' except that all tabs have been expanded to spaces, and
* the total length has been truncated to 60 chars.
*/
char *padline(line)
char *line;
{
static char newline[61];
char *p1;
int pos=0,nxtpos;
for(p1=line; pos<sizeof(newline)-1 && *p1; p1++ ) {
if( *p1 == '\t' ) {
nxtpos = pos+8-pos%8;
while(pos<sizeof(newline)-1 && pos <= nxtpos)
newline[pos++] = ' ';
} else if( *p1 != '\n' )
newline[pos++]= *p1;
}
newline[pos] = '\0';
return(newline);
}
/* ----------------------------------------------------------------------
* dumplist:
* Outputs the current location counter, bytebuf[] array, and
* the string 'txt' to the listing file.
* This routine is called for every source line encountered in the
* source file. (Only in pass 2, and if listing is turned on).
*
*/
void dumplist(txt, show)
char *txt;
{
int i,j;
fprintf(listing,show?"%04X: ":" ",lc);
j=0;
for(i=0; i<bytecount; i++ ) {
fprintf(listing,"%02X ",bytebuf[i]);
if( ++j >= 4 ) {
j = 0;
fprintf(listing,"\n ");
}
}
while(++j <= 4)
fprintf(listing," ");
fprintf(listing," %s\n",padline(txt));
}
/* ----------------------------------------------------------------------
* gen* routines:
* Place information into the bytebuf[] array, and also
* call emitbyte with the byte.
*
*/
void genbyte(b)
int b;
{
if( bytecount < sizeof(bytebuf) )
bytebuf[bytecount++] = b;
emitbyte(b);
}
void genstr(s)
char *s;
{
while( *s )
genbyte(*s++);
}
void genword(w)
long w;
{
genbyte( (w & 0xff00) >> 8 );
genbyte( (w & 0x00ff) );
}
/*
* makeop:
* This function makes an opcode based on the instruction symbol table
* entry, and an addressing mode structure.
* This function is called from both passes, but
* only generates code in pass 2.
*
* Resultant opcode bytes are passed to genbyte().
*
* Returns the nuumber of bytes that the instruction
* occupies.
*/
int makeop(op, m, add)
struct opcode *op;
struct mode *m;
{
unsigned newop;
if( m == NULL ) {
if(pass2) genbyte(op->bytes[0+add]);
return(1);
}
if( pass2 ) {
newop = op->bytes[ get_md(*m)+add ] | get_ov(*m);
genbyte(newop);
if( get_sz(*m) > 0 ) genbyte( get_b1(*m) );
if( get_sz(*m) > 1 ) genbyte( get_b2(*m) );
}
return (get_sz(*m)+1);
}
yytabelem yyexca[] ={
-1, 1,
0, -1,
-2, 0,
};
#define YYNPROD 161
#define YYLAST 742
yytabelem yyact[] = {
9, 286, 168, 182, 183, 184, 185, 186, 187, 188,
189, 208, 229, 182, 183, 184, 185, 186, 187, 188,
189, 6, 121, 120, 226, 289, 228, 263, 262, 69,
282, 68, 284, 283, 70, 192, 10, 182, 183, 184,
185, 186, 187, 188, 189, 116, 117, 190, 302, 301,
191, 269, 276, 243, 304, 156, 303, 288, 121, 120,
9, 287, 270, 154, 75, 113, 112, 111, 110, 109,
105, 108, 106, 59, 60, 61, 62, 63, 64, 65,
170, 253, 252, 173, 170, 107, 226, 4, 171, 69,
56, 68, 158, 172, 70, 5, 10, 139, 300, 292,
291, 271, 255, 79, 69, 199, 68, 254, 297, 70,
224, 249, 245, 151, 280, 69, 235, 68, 212, 69,
70, 68, 83, 87, 70, 211, 210, 209, 95, 206,
69, 205, 68, 204, 296, 70, 203, 201, 198, 223,
69, 197, 68, 196, 295, 70, 194, 141, 142, 193,
129, 167, 157, 248, 95, 166, 147, 233, 69, 231,
68, 180, 69, 70, 68, 179, 169, 70, 178, 69,
169, 68, 74, 69, 70, 68, 126, 230, 70, 138,
69, 274, 68, 250, 234, 70, 90, 66, 76, 77,
78, 82, 86, 89, 131, 132, 133, 134, 58, 84,
115, 73, 57, 3, 119, 238, 55, 114, 148, 104,
69, 143, 68, 135, 261, 70, 260, 163, 128, 88,
160, 69, 8, 68, 7, 146, 70, 2, 1, 0,
236, 0, 0, 0, 0, 0, 164, 122, 123, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 12, 14, 15, 13, 18,
47, 35, 36, 23, 22, 24, 51, 21, 48, 50,
42, 25, 49, 43, 44, 45, 41, 40, 52, 53,
54, 11, 26, 19, 39, 38, 27, 28, 29, 30,
31, 32, 37, 46, 16, 33, 20, 34, 17, 225,
244, 155, 121, 120, 96, 97, 98, 99, 100, 101,
102, 103, 72, 71, 6, 12, 14, 15, 13, 18,
47, 35, 36, 23, 22, 24, 51, 21, 48, 50,
42, 25, 49, 43, 44, 45, 41, 40, 52, 53,
54, 11, 26, 19, 39, 38, 27, 28, 29, 30,
31, 32, 37, 46, 16, 33, 20, 34, 17, 75,
153, 225, 152, 0, 96, 97, 98, 99, 100, 101,
102, 103, 72, 71, 92, 200, 0, 91, 0, 96,
97, 98, 99, 100, 101, 102, 103, 72, 71, 278,
96, 97, 98, 99, 100, 101, 102, 103, 72, 71,
92, 0, 72, 71, 181, 96, 97, 98, 99, 100,
101, 102, 103, 72, 71, 96, 97, 98, 99, 100,
101, 102, 103, 72, 71, 136, 81, 257, 246, 240,
96, 97, 98, 99, 100, 101, 102, 103, 162, 67,
67, 72, 71, 75, 85, 72, 71, 258, 0, 0,
75, 0, 72, 71, 0, 0, 72, 71, 0, 118,
80, 0, 0, 72, 71, 0, 93, 127, 127, 130,
130, 130, 130, 130, 0, 0, 0, 0, 0, 0,
0, 0, 94, 94, 0, 0, 159, 281, 165, 159,
0, 0, 0, 72, 71, 0, 176, 177, 0, 124,
125, 0, 290, 0, 72, 71, 0, 0, 140, 140,
140, 0, 145, 149, 137, 0, 0, 0, 144, 150,
0, 161, 298, 299, 173, 170, 0, 0, 220, 171,
175, 305, 174, 0, 172, 0, 0, 0, 0, 173,
170, 0, 0, 195, 171, 175, 0, 174, 0, 172,
0, 0, 0, 0, 0, 0, 202, 0, 0, 0,
0, 207, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 213, 214, 215, 216,
217, 218, 219, 0, 0, 0, 0, 0, 0, 0,
0, 169, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 237, 239, 237, 169, 0, 264, 0,
0, 0, 0, 0, 0, 0, 0, 165, 259, 222,
227, 0, 0, 0, 0, 221, 0, 0, 275, 0,
0, 0, 0, 0, 232, 0, 0, 0, 285, 0,
242, 0, 247, 0, 251, 0, 241, 0, 0, 0,
256, 0, 0, 0, 0, 0, 0, 165, 0, 0,
0, 0, 0, 0, 0, 265, 0, 266, 267, 268,
0, 0, 0, 0, 272, 273, 0, 0, 237, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 277,
279, 0, 0, 0, 0, 0, 0, 0, 237, 237,
0, 0, 0, 0, 0, 0, 0, 237, 0, 0,
0, 0, 0, 0, 0, 293, 0, 0, 0, 0,
0, 294
};
yytabelem yypact[] = {
-10, -1000, -10, -1000, 32, -1000, -1000, 192, 188, -1000,
-185, -1000, 129, 129, -246, -246, -246, 140, 133, 133,
-246, 64, 90, -240, -237, 21, -238, -1000, -1000, -241,
-242, -243, -244, -245, -246, -265, -265, -265, 129, 129,
129, 129, 129, 129, 129, 129, 129, 115, -301, -301,
-301, 100, 49, -247, -9, -1000, 50, -1000, -1000, 129,
181, 129, 129, -303, -322, -1000, -1000, 502, -1000, 129,
129, -1000, -1000, -1000, -1000, 124, -1000, -1000, -1000, -1000,
121, 502, -1000, -1000, -1000, 117, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -278, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -263, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -279,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, 502, -1000, -1000,
502, -1000, -1000, -1000, -1000, -1000, 105, 102, -278, -1000,
99, -1000, -1000, -1000, 97, 94, -1000, -1000, -1000, 61,
93, -278, 92, 89, 87, 85, -302, -1000, -1000, 502,
83, -1000, -1000, 82, -1000, 502, -1000, 81, 74, 129,
129, 129, 129, 129, 129, 129, 487, 42, 75, 51,
-21, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
134, 116, -1000, 122, 149, 72, 129, 129, 129, -11,
68, 118, 67, 148, -301, 18, 17, 63, 58, 170,
129, 129, -296, -1000, -1000, 42, 42, 42, 46, 46,
-1000, -1000, -1000, -278, 129, -1000, 129, -1000, -301, -301,
-262, -248, 57, 129, 129, 146, -1000, 502, -1000, 502,
-1000, -1000, -1000, -278, -1000, -259, -1000, -1000, 129, 79,
129, -1000, -280, -312, -249, -253, -1000, -1000, -1000, 502,
-1000, -289, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, 129, 56, 55, 129, -1000, -1000, -1000, -1000, -1000,
129, -1000, 101, 91, 65, -1000, -1000, -1000, -1000, -1000,
-1000, 129, 129, 54, -1000, -264, -254, -256, -1000, -1000,
129, -1000, -1000, -1000, -1000, -1000 };
yytabelem yypgo[]={
0, 228, 227, 203, 87, 95, 224, 222, 92, 220,
217, 426, 216, 214, 460, 236, 187, 172, 103, 199,
186, 200, 176, 150, 213, 97, 211, 208, 404, 466,
459, 230, 205, 204 };
yytabelem yyr1[]={
0, 1, 2, 2, 3, 3, 5, 5, 5, 6,
6, 6, 6, 6, 6, 6, 8, 12, 13, 13,
4, 9, 9, 9, 9, 10, 10, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 11, 11, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 17, 17,
17, 17, 18, 18, 19, 19, 19, 25, 26, 26,
27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
27, 27, 27, 20, 20, 20, 20, 21, 21, 21,
24, 24, 24, 24, 31, 32, 30, 30, 33, 33,
29, 29, 29, 29, 29, 29, 29, 29, 28, 28,
28, 28, 28, 28, 28, 28, 14, 15, 16, 22,
23 };
yytabelem yyr2[]={
0, 3, 4, 2, 7, 3, 5, 5, 3, 7,
7, 7, 7, 11, 11, 5, 3, 5, 3, 3,
3, 7, 7, 3, 3, 7, 3, 3, 7, 5,
7, 7, 7, 7, 7, 7, 7, 3, 3, 3,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 11,
11, 5, 3, 3, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
15, 15, 15, 15, 11, 11, 11, 11, 7, 7,
9, 9, 7, 9, 7, 9, 9, 7, 7, 7,
7, 7, 9, 7, 7, 9, 9, 9, 11, 9,
7, 7, 9, 3, 3, 3, 5, 3, 3, 3,
11, 13, 13, 15, 3, 3, 5, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3 };
yytabelem yychk[]={
-1000, -1, -2, -3, -4, -5, 324, -6, -7, 10,
46, 291, 265, 268, 266, 267, 304, 308, 269, 293,
306, 277, 274, 273, 275, 281, 292, 296, 297, 298,
299, 300, 301, 305, 307, 271, 272, 302, 295, 294,
287, 286, 280, 283, 284, 285, 303, 270, 278, 282,
279, 276, 288, 289, 290, -3, 58, 10, 10, 258,
259, 260, 261, 262, 263, 264, -16, -11, 42, 40,
45, 324, 323, -16, -17, 310, -17, -17, -17, -18,
-14, -11, -17, -18, -19, 311, -17, -18, -19, -17,
-20, 313, 310, -29, -14, 64, 315, 316, 317, 318,
319, 320, 321, 322, -20, 310, 309, 64, 309, 310,
310, 310, 310, 310, -17, -21, 310, 311, -30, -33,
324, 323, -21, -21, -14, -14, -22, -11, -22, -23,