comparison lwasm/insn_indexed.c @ 230:0df2a39a268c

Added --6809/--6309 switches and some cleanups in error reporting
author lost
date Fri, 12 Jun 2009 03:18:32 +0000
parents bae1e3ecdce1
children
comparison
equal deleted inserted replaced
229:59a138df0401 230:0df2a39a268c
33 #include "instab.h" 33 #include "instab.h"
34 #include "expr.h" 34 #include "expr.h"
35 35
36 void insn_indexed_aux(asmstate_t *as, lwasm_line_t *l, const char **p, int *b1, int *b2, int *b3) 36 void insn_indexed_aux(asmstate_t *as, lwasm_line_t *l, const char **p, int *b1, int *b2, int *b3)
37 { 37 {
38 struct opvals { char *opstr; int pb; };
39
38 static const char *regs = "X Y U S W PCRPC "; 40 static const char *regs = "X Y U S W PCRPC ";
39 static const struct { char *opstr; int pb; } simpleindex[] = 41 static const struct opvals simpleindex[] =
40 { 42 {
41 {",x", 0x84}, {",y", 0xa4}, {",u", 0xc4}, {",s", 0xe4}, 43 {",x", 0x84}, {",y", 0xa4}, {",u", 0xc4}, {",s", 0xe4},
42 {",x+", 0x80}, {",y+", 0xa0}, {",u+", 0xc0}, {",s+", 0xe0}, 44 {",x+", 0x80}, {",y+", 0xa0}, {",u+", 0xc0}, {",s+", 0xe0},
43 {",x++", 0x81}, {",y++", 0xa1}, {",u++", 0xc1}, {",s++", 0xe1}, 45 {",x++", 0x81}, {",y++", 0xa1}, {",u++", 0xc1}, {",s++", 0xe1},
44 {",-x", 0x82}, {",-y", 0xa2}, {",-u", 0xc2}, {",-s", 0xe2}, 46 {",-x", 0x82}, {",-y", 0xa2}, {",-u", 0xc2}, {",-s", 0xe2},
62 {"[w,x]", 0x9e}, {"[w,y]", 0xbe}, {"[w,u]", 0xde}, {"[w,s]", 0xfe}, 64 {"[w,x]", 0x9e}, {"[w,y]", 0xbe}, {"[w,u]", 0xde}, {"[w,s]", 0xfe},
63 {"[,w]", 0x90}, {"[,w++]", 0xd0}, {"[,--w]", 0xf0}, 65 {"[,w]", 0x90}, {"[,w++]", 0xd0}, {"[,--w]", 0xf0},
64 66
65 { "", -1 } 67 { "", -1 }
66 }; 68 };
69
70 static const char *regs9 = "X Y U S PCRPC ";
71 static const struct opvals simpleindex9[] =
72 {
73 {",x", 0x84}, {",y", 0xa4}, {",u", 0xc4}, {",s", 0xe4},
74 {",x+", 0x80}, {",y+", 0xa0}, {",u+", 0xc0}, {",s+", 0xe0},
75 {",x++", 0x81}, {",y++", 0xa1}, {",u++", 0xc1}, {",s++", 0xe1},
76 {",-x", 0x82}, {",-y", 0xa2}, {",-u", 0xc2}, {",-s", 0xe2},
77 {",--x", 0x83}, {",--y", 0xa3}, {",--u", 0xc3}, {",--s", 0xe3},
78 {"a,x", 0x86}, {"a,y", 0xa6}, {"a,u", 0xc6}, {"a,s", 0xe6},
79 {"b,x", 0x85}, {"b,y", 0xa5}, {"b,u", 0xc5}, {"b,s", 0xe5},
80 {"d,x", 0x8b}, {"d,y", 0xab}, {"d,u", 0xcb}, {"d,s", 0xed},
81
82 {"[,x]", 0x94}, {"[,y]", 0xb4}, {"[,u", 0xd4}, {"[,s]", 0xf4},
83 {"[,x++]", 0x91}, {"[,y++]", 0xb1}, {"[,u++]", 0xd1}, {"[,s++]", 0xf1},
84 {"[,--x]", 0x93}, {"[,--y]", 0xb3}, {"[,--u]", 0xd3}, {"[,--s]", 0xf3},
85 {"[a,x]", 0x96}, {"[a,y]", 0xb6}, {"[a,u]", 0xd6}, {"[a,s]", 0xf6},
86 {"[b,x]", 0x95}, {"[b,y]", 0xb5}, {"[b,u]", 0xd5}, {"[b,s]", 0xf5},
87 {"[d,x]", 0x9b}, {"[d,y]", 0xbb}, {"[d,u]", 0xdb}, {"[d,s]", 0xfd},
88
89 { "", -1 }
90 };
67 char stbuf[25]; 91 char stbuf[25];
68 int i, j, rn; 92 int i, j, rn;
69 int f8 = 0, f16 = 0, f0 = 0; 93 int f8 = 0, f16 = 0, f0 = 0;
70 int r, v; 94 int r, v;
71 int indir = 0; 95 int indir = 0;
72 int fs8 = 0, fs16 = 0; 96 int fs8 = 0, fs16 = 0;
97 const struct opvals *simples;
98 const char *reglist;
99
100 if (as -> no6309)
101 {
102 simples = simpleindex9;
103 reglist = regs9;
104 }
105 else
106 {
107 simples = simpleindex;
108 reglist = regs;
109 }
73 110
74 // initialize output bytes 111 // initialize output bytes
75 *b1 = *b2 = *b3 = -1; 112 *b1 = *b2 = *b3 = -1;
76 113
77 // fetch out operand for lookup 114 // fetch out operand for lookup
86 123
87 // now look up operand in "simple" table 124 // now look up operand in "simple" table
88 if (!*((*p) + i) || isspace(*((*p) + i))) 125 if (!*((*p) + i) || isspace(*((*p) + i)))
89 { 126 {
90 // do simple lookup 127 // do simple lookup
91 for (j = 0; simpleindex[j].opstr[0]; j++) 128 for (j = 0; simples[j].opstr[0]; j++)
92 { 129 {
93 if (!strcasecmp(stbuf, simpleindex[j].opstr)) 130 if (!strcasecmp(stbuf, simples[j].opstr))
94 break; 131 break;
95 } 132 }
96 if (simpleindex[j].opstr[0]) 133 if (simples[j].opstr[0])
97 { 134 {
98 *b1 = simpleindex[j].pb; 135 *b1 = simples[j].pb;
99 (*p) += i; 136 (*p) += i;
100 return; 137 return;
101 } 138 }
102 } 139 }
103 140
187 l -> fsize = 0; 224 l -> fsize = 0;
188 return; 225 return;
189 } 226 }
190 227
191 // now get the register 228 // now get the register
192 rn = lwasm_lookupreg3(regs, p); 229 rn = lwasm_lookupreg3(reglist, p);
193 if (rn < 0) 230 if (rn < 0)
194 { 231 {
195 *b1 = 0; 232 *b1 = 0;
196 l -> fsize = 0; 233 l -> fsize = 0;
197 register_error(as, l, 1, "Bad register"); 234 register_error(as, l, 1, "Bad register");