head	1.1;
access;
symbols;
locks
	david:1.1; strict;
comment	@ * @;


1.1
date	97.06.04.02.59.13;	author david;	state Exp;
branches;
next	;


desc
@Initial Version.
@


1.1
log
@Initial revision
@
text
@%{
#include <stdio.h>
#include "xasm.h"
#include "symbols.h"
static char *ProperyId = "$Id$";
extern char *labels;
extern char *lptrs;
extern char objcode[BUFSIZ];
%}
%token ID HEXNUMBER BINARYNUMBER DECIMALNUMBER STRING

%token ADD ADDC ANL ORL XRL INC CLR CPL DA SWAP RL RR RRC RLC
%token IN OUTL INS MOVD ANLD ORLD DEC JMP JMPP DJNZ
%token JC JNC JZ JNZ JT0 JNT0 JT1 JNT1 JF0 JF1 JNI
%token JB0 JB1 JB2 JB3 JB4 JB5 JB6 JB7
%token CALL RET RETR MOV XCH XCHD MOVX MOVP MOVP3 STRT STOP EN DIS
%token SEL ENT0 NOP

%token A BUS C CLK CNT F0 F1 I JTF MB0 MB1 PSW RB0 RB1 T TCNT TCNTI
%token R0 R1 R2 R3 R4 R5 R6 R7 P1 P2 P4 P5 P6 P7
%token DB DS DW END EQU IF INCLUDE ORG
%token AND HIGH LOW NOT OR SHL SHR
%left '+' '-' OR
%left '*' '/' AND
%start Opcode
%%
Opcode : psuedop
       | instr
       ;
psuedop : DB DBData		   { db( 0, 0, lptrs ); /* EOF Signal */ }
	| DS Data                  { ds( $2, lptrs ); }
	| DW DWData		   { dw( 0, 0, lptrs ); /* EOF Signal */ }
	| END Data                 { xpend( $2, lptrs ); }
	| END                      { xpend( 0, lptrs ); }
	| EQU Data                 { equ( labels, $2, lptrs ); }
	| IF expr		   { aif( $2, lptrs ); }
	| INCLUDE STRING	   { include( $2, lptrs ); }
	| ORG Data                 { org( $2, lptrs ); }
	;
DBData : DBData ',' expr   { db( $3, 1, lptrs ); }
       | expr              { db( $1, 1, lptrs ); }
       | DBData ',' STRING { db( $3, 2, lptrs ); }
       | STRING		   { db( $1, 2, lptrs ); }
       ;
DWData : DWData ',' expr   { dw( $3, 1, lptrs ); }
       | expr              { dw( $1, 1, lptrs ); }
       ;
instr  : ADD A ',' Rr              { strcpy(objcode,or(0x68,$4)); }
       | ADD A ',' '@@' Ri          { strcpy(objcode,or(0x60,$5)); }
       | ADD A ',' '#' Data        { data( 0x03, $5 ); }
       | ADDC A ',' Rr             { strcpy(objcode,or(0x78,$4)); }
       | ADDC A ',' '@@' Ri         { strcpy(objcode,or(0x70,$5)); }
       | ADDC A ',' '#' Data       { data( 0x13, $5 ); }
       | ANL A ',' Rr              { strcpy(objcode,or(0x58,$4)); }
       | ANL A ',' '@@' Ri          { strcpy(objcode,or(0x50,$5)); }
       | ANL A ',' '#' Data        { data( 0x53, $5 ); }
       | ANL BUS ',' '#' Data      { data( 0x98, $5 ); }
       | ANL Pp1 ',' '#' Data      { data( 0x98 | $2, $5 ); }
       | ANLD Pp4 ',' A            { strcpy(objcode,or(0x9C,$2)); }
       | CALL Address              { call( $2 ); }
       | CLR A                     { strcpy( objcode, "27" ); }
       | CLR C                     { strcpy( objcode, "97" ); }
       | CLR F1                    { strcpy( objcode, "A5" ); }
       | CLR F0                    { strcpy( objcode, "85" ); }
       | CPL A                     { strcpy( objcode, "37" ); }
       | CPL C                     { strcpy( objcode, "A7" ); }
       | CPL F0                    { strcpy( objcode, "95" ); }
       | CPL F1                    { strcpy( objcode, "B5" ); }
       | DA A                      { strcpy( objcode, "57" ); }
       | DEC A                     { strcpy( objcode, "07" ); }
       | DEC Rr                    { strcpy(objcode,or(0xC8,$2)); }
       | DIS I                     { strcpy( objcode, "15" ); }
       | DIS TCNTI                 { strcpy( objcode, "35" ); }
       | DJNZ Rr ',' Address       { addr( 0xE8 | $2, $4 ); }
       | EN I                      { strcpy( objcode, "05" ); }
       | EN TCNTI                  { strcpy( objcode, "25" ); }
       | ENT0 CLK                  { strcpy( objcode, "75" ); }
       | IN A ',' Pp1              { strcpy(objcode,or(0x08,$4)); }
       | INC A                     { strcpy( objcode, "17" ); }
       | INC Rr                    { strcpy(objcode,or(0x18,$2)); }
       | INC '@@' Ri                { strcpy(objcode,or(0x10,$3)); }
       | INS A ',' BUS             { strcpy( objcode, "08" ); }
       | JB0 Address               { addr( 0x12, $2 ); }
       | JB1 Address               { addr( 0x32, $2 ); }
       | JB2 Address               { addr( 0x52, $2 ); }
       | JB3 Address               { addr( 0x72, $2 ); }
       | JB4 Address               { addr( 0x92, $2 ); }
       | JB5 Address               { addr( 0xB2, $2 ); }
       | JB6 Address               { addr( 0xD2, $2 ); }
       | JB7 Address               { addr( 0xF2, $2 ); }
       | JC Address                { addr( 0xF6, $2 ); }
       | JF0 Address               { addr( 0xB6, $2 ); }
       | JF1 Address               { addr( 0x76, $2 ); }
       | JMP Address               { jmp( $2 ); }
       | JMPP '@@' A                { strcpy( objcode, "B3" ); }
       | JNC Address               { addr( 0xE6, $2 ); }
       | JNI Address               { addr( 0x86, $2 ); }
       | JNT0 Address              { addr( 0x26, $2 ); }
       | JNT1 Address              { addr( 0x46, $2 ); }
       | JNZ Address               { addr( 0x96, $2 ); }
       | JTF Address               { addr( 0x16, $2 ); }
       | JT0 Address               { addr( 0x36, $2 ); }
       | JT1 Address               { addr( 0x56, $2 ); }
       | JZ Address                { addr( 0xC6, $2 ); }
       | MOV A ',' '#' Data        { data( 0x23, $5 ); }
       | MOV A ',' PSW             { strcpy( objcode, "C7" ); }
       | MOV A ',' Rr              { strcpy(objcode,or(0xF8,$4)); }
       | MOV A ',' '@@' Ri          { strcpy(objcode,or(0xF0,$5)); }
       | MOV A ',' T               { strcpy( objcode, "42" ); }
       | MOV PSW ',' A             { strcpy( objcode, "D7" ); }
       | MOV Rr ',' A              { strcpy(objcode,or(0xA8,$2)); }
       | MOV Rr ',' '#' Data       { data( 0xB8 | $2, $5 ); }
       | MOV '@@' Ri ',' A          { strcpy(objcode,or(0xA0,$3)); }
       | MOV '@@' Ri ',' '#' Data   { data( 0xB0 | $3, $6 ); }
       | MOV T ',' A               { strcpy( objcode, "62" ); }
       | MOVD A ',' Pp4            { strcpy(objcode,or(0x0C,$4)); }
       | MOVD Pp4 ',' A            { strcpy(objcode,or(0x3C,$2)); }
       | MOVP A ',' '@@' A          { strcpy( objcode, "A3" ); }
       | MOVP3 A ',' '@@' A         { strcpy( objcode, "E3" ); }
       | MOVX A ',' '@@' Ri         { strcpy(objcode,or(0x80,$5)); }
       | MOVX '@@' Ri ',' A         { strcpy(objcode,or(0x90,$3)); }
       | NOP                       { strcpy( objcode, "00" ); }
       | ORL A ',' Rr              { strcpy(objcode,or(0x48,$4)); }
       | ORL A ',' '@@' Ri          { strcpy(objcode,or(0x40,$5)); }
       | ORL A ',' '#' Data        { data( 0x43, $5 ); }
       | ORL BUS ',' '#' Data      { data( 0x88, $5 ); }
       | ORL Pp1 ',' '#' Data      { data( 0x88 | $2, $5 ); }
       | ORLD Pp4 ',' A            { strcpy(objcode,or(0x8C,$2)); }
       | OUTL BUS ',' A            { strcpy( objcode, "02" ); }
       | OUTL Pp1 ',' A            { strcpy(objcode,or(0x38,$2)); }
       | RET                       { strcpy( objcode, "83" ); }
       | RETR                      { strcpy( objcode, "93" ); }
       | RL A                      { strcpy( objcode, "E7" ); }
       | RLC A                     { strcpy( objcode, "F7" ); }
       | RR A                      { strcpy( objcode, "77" ); }
       | RRC A                     { strcpy( objcode, "67" ); }
       | SEL MB0                   { strcpy( objcode, "E5" ); }
       | SEL MB1                   { strcpy( objcode, "F5" ); }
       | SEL RB0                   { strcpy( objcode, "C5" ); }
       | SEL RB1                   { strcpy( objcode, "D5" ); }
       | STOP TCNT                 { strcpy( objcode, "65" ); }
       | STRT CNT                  { strcpy( objcode, "45" ); }
       | STRT T                    { strcpy( objcode, "55" ); }
       | SWAP A                    { strcpy( objcode, "47" ); }
       | XCH A ',' Rr              { strcpy(objcode,or(0x28,$4)); }
       | XCH A ',' '@@' Ri          { strcpy(objcode,or(0x20,$5)); }
       | XCHD A ',' '@@' Ri         { strcpy(objcode,or(0x30,$5)); }
       | XRL A ',' Rr              { strcpy(objcode,or(0xD8,$4)); }
       | XRL A ',' '@@' Ri          { strcpy(objcode,or(0xD0,$5)); }
       | XRL A ',' '#' Data        { data( 0xD3, $5 ); }
       ;
Rr : R0    { $$ = 0; }
   | R1    { $$ = 1; }
   | R2    { $$ = 2; }
   | R3    { $$ = 3; }
   | R4    { $$ = 4; }
   | R5    { $$ = 5; }
   | R6    { $$ = 6; }
   | R7    { $$ = 7; }
   ;
Ri : R0    { $$ = 0; }
   | R1    { $$ = 1; }
   ;
Pp1 : P1    { $$ = 1; }
    | P2    { $$ = 2; }
    ;
Pp4 : P4    { $$ = 0; }
    | P5    { $$ = 1; }
    | P6    { $$ = 2; }
    | P7    { $$ = 3; }
    ;
Data : expr     { $$ = $1; }
     ;
Address : expr  { $$ = $1; }
        ;
expr : ID                    {
			     struct symtab *sp;
                             if ( (sp = symfind( (char *) $1, 1 )) == NULL )
				{
				xerror( "propery: Undefined Symbol" );
				$$ = -1;
				}
			      else
				$$ = sp->value;
			     }
     | HEXNUMBER                 { $$ = $1; }
     | BINARYNUMBER              { $$ = $1; }
     | DECIMALNUMBER             { $$ = $1; }
     | '$'                       { $$ = loc;}
     | expr '*' expr             { $$ = $1 * $3; }
     | expr '/' expr             { $$ = $1 / $3; }
     | expr '+' expr             { $$ = $1 + $3; }
     | expr '-' expr             { $$ = $1 - $3; }
     | '(' expr ')'              { $$ = $2; }
     | '-' expr %prec  '-'       { $$ = - $2; }
     | expr AND expr		 { $$ = $1 & $3; }
     | expr OR expr		 { $$ = $1 | $3; }
     | NOT expr %prec NOT	 { $$ = ~ $2; }
     | HIGH expr		 { $$ = ($2 >> 8) & 0xff; }
     | LOW expr			 { $$ = $2 & 0xff; }
     | expr SHL expr		 { $$ = $1 << $3; }
     | expr SHR expr		 { $$ = $1 >> $3; }
     ;
%%
@
