URL
https://opencores.org/ocsvn/tms1000/tms1000/trunk
Subversion Repositories tms1000
[/] [tms1000/] [trunk/] [assembler/] [casmy.y] - Rev 5
Go to most recent revision | Compare with Previous | Blame | View Log
/*
casm.y: grammar
CASM is an assembler for the TMS1000 processor.
*/
%{
#include <stdio.h>
#include "symtab.h"
#include "casm.h"
int bitreverse4[]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
int bitreverse2[]={0,2,1,3};
%}
%union {
int integer;
char *string;
}
%token <integer> INTEGER
%token <string> IDENT
%token BR
%token CALL
%token CALLL
%token CLO
%token COMX
%token LDP
%token LDX
%token SBIT
%token RBIT
%token RETN
%token RSTR
%token SETR
%token TDO
%token ALEC
%token ALEM
%token AMAAC
%token A6AAC
%token A8AAC
%token A10AAC
%token CLA
%token CPAIZ
%token DAN
%token DMAN
%token DYN
%token IA
%token IMAC
%token IYC
%token KNEZ
%token MNEZ
%token SAMAN
%token TAM
%token TAMIY
%token TAMZA
%token TAY
%token TBIT1
%token TCY
%token TCMIY
%token TKA
%token TMA
%token TMY
%token TYA
%token XMA
%token YNEA
%token YNEC
%token BL
%token ROM
%token SYMTAB
%type <integer> expr
%%
line : label instruction
| label
| instruction
| pseudo_op
|
| error
;
label: IDENT ':' { do_label ($1); }
;
expr : INTEGER { $$ = $1; }
| IDENT { if (pass == 1)
$$ = 0;
else if (! lookup_symbol (symtab, $1, &$$))
{
error ("undefined symbol '%s'\n", $1);
$$ = 0;
}
}
;
pseudo_op : ps_rom
| ps_symtab
;
ps_rom : '.' ROM expr { /*$3 = range ($3, 0, MAXGROUP * MAXROM - 1);
group = dsg = ($3 >> 3);
rom = dsr = ($3 & 7); */
rom = $3;
pc = 0;
last_instruction_type = OTHER_INST;
printf (" %d", $3); }
;
ps_symtab : '.' SYMTAB { symtab_flag = 1; }
;
instruction : inst_br
| inst_bl
| inst_call
| inst_calll
| inst_clo
| inst_comx
| inst_ldp
| inst_ldx
| inst_sbit
| inst_rbit
| inst_retn
| inst_rstr
| inst_setr
| inst_tdo
| inst_alec
| inst_alem
| inst_amaac
| inst_a6aac
| inst_a8aac
| inst_a10aac
| inst_cla
| inst_cpaiz
| inst_dan
| inst_dman
| inst_dyn
| inst_ia
| inst_imac
| inst_iyc
| inst_knez
| inst_mnez
| inst_saman
| inst_tam
| inst_tamiy
| inst_tamza
| inst_tay
| inst_tbit1
| inst_tcy
| inst_tcmiy
| inst_tka
| inst_tma
| inst_tmy
| inst_tya
| inst_xma
| inst_ynea
| inst_ynec
;
inst_br : BR expr { emit (0x80 | ($2 & 0x3f)); } ;
inst_bl : BL expr { emit (0x10 | bitreverse4[(($2 & 0x3c0) >> 6)]);
pc = ((pc != 31) && ((pc >> 4) != 0) && (((pc & 0xf) == 15) || ((pc >> 4) != 3))) ? (pc << 1) : (pc << 1)+1;
pc = pc & 0x3f;
emit (0x80 | ($2 & 0x3f)); } ;
inst_call : CALL expr { emit (0xc0 | ($2 & 0x3f)); } ;
inst_calll : CALLL expr { emit (0x10 | bitreverse4[(($2 & 0x3c0) >> 6)]);
pc = ((pc != 31) && ((pc >> 4) != 0) && (((pc & 0xf) == 15) || ((pc >> 4) != 3))) ? (pc << 1) : (pc << 1)+1;
pc = pc & 0x3f;
emit (0xc0 | ($2 & 0x3f)); } ;
inst_clo : CLO { emit (0x0b); } ;
inst_comx : COMX { emit (0x00); } ;
inst_ldp : LDP expr { emit (0x10 | bitreverse4[($2 & 0xf)]); } ;
inst_ldx : LDX expr { emit (0x3c | bitreverse2[($2 & 0x3)]); } ;
inst_sbit : SBIT expr { emit (0x30 | bitreverse2[($2 & 0x3)]); } ;
inst_rbit : RBIT expr { emit (0x34 | bitreverse2[($2 & 0x3)]); } ;
inst_retn : RETN { emit (0x0f); } ;
inst_rstr : RSTR { emit (0x0c); } ;
inst_setr : SETR { emit (0x0d); } ;
inst_tdo : TDO { emit (0x0a); } ;
inst_alec : ALEC expr { emit (0x70 | bitreverse4[($2 & 0xf)]); } ;
inst_alem : ALEM { emit (0x29); } ;
inst_amaac : AMAAC { emit (0x25); } ;
inst_a6aac : A6AAC { emit (0x06); } ;
inst_a8aac : A8AAC { emit (0x01); } ;
inst_a10aac : A10AAC { emit (0x05); } ;
inst_cla : CLA { emit (0x2f); } ;
inst_cpaiz : CPAIZ { emit (0x2d); } ;
inst_dan : DAN { emit (0x07); } ;
inst_dman : DMAN { emit (0x2a); } ;
inst_dyn : DYN { emit (0x2c); } ;
inst_ia : IA { emit (0x0e); } ;
inst_imac : IMAC { emit (0x28); } ;
inst_iyc : IYC { emit (0x2b); } ;
inst_knez : KNEZ { emit (0x09); } ;
inst_mnez : MNEZ { emit (0x26); } ;
inst_saman : SAMAN { emit (0x27); } ;
inst_tam : TAM { emit (0x03); } ;
inst_tamiy : TAMIY { emit (0x20); } ;
inst_tamza : TAMZA { emit (0x04); } ;
inst_tay : TAY { emit (0x24); } ;
inst_tbit1 : TBIT1 expr { emit (0x38 | bitreverse2[($2 & 0x3)]); } ;
inst_tcy : TCY expr { emit (0x40 | bitreverse4[($2 & 0xf)]); } ;
inst_tcmiy : TCMIY expr { emit (0x60 | bitreverse4[($2 & 0xf)]); } ;
inst_tka : TKA { emit (0x08); } ;
inst_tma : TMA { emit (0x21); } ;
inst_tmy : TMY { emit (0x22); } ;
inst_tya : TYA { emit (0x23); } ;
inst_xma : XMA { emit (0x2e); } ;
inst_ynea : YNEA { emit (0x02); } ;
inst_ynec : YNEC expr { emit (0x50 | bitreverse4[($2 & 0xf)]); } ;
%%
Go to most recent revision | Compare with Previous | Blame | View Log