comparison lwasm/insn_gen.c @ 470:2c1c5dd84024

Add << prefix to force 5 bit offsets in indexed modes Rounding out the compliment of operand size prefixes, we now have "<<" to mean "force 5 bits". According to Steve Bjork, this was the "official" way to do this since 1980. However, I have no official Motorola source for that. It does suggest that the choice of "<<" is consistent with other (historical) assemblers, though. Either way, it seems the most logical choice while avoiding any conflicts with legal source code, so "<<" it is.
author William Astle <lost@l-w.ca>
date Mon, 23 Jul 2018 17:45:18 -0600
parents 3948c874901b
children eac8f5f0867d
comparison
equal deleted inserted replaced
469:9393a6b8886c 470:2c1c5dd84024
63 optr2 = *p; 63 optr2 = *p;
64 if (**p == '<') 64 if (**p == '<')
65 { 65 {
66 (*p)++; 66 (*p)++;
67 l -> lint2 = 0; 67 l -> lint2 = 0;
68 if (**p == '<')
69 {
70 *p = optr2;
71 goto indexed;
72 }
68 } 73 }
69 // for compatibility with asxxxx 74 // for compatibility with asxxxx
70 // * followed by a digit, alpha, or _, or ., or ?, or another * is "f8" 75 // * followed by a digit, alpha, or _, or ., or ?, or another * is "f8"
71 else if (**p == '*') 76 else if (**p == '*')
72 { 77 {
173 { 178 {
174 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2 + elen; 179 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2 + elen;
175 } 180 }
176 else if (l -> lint2 == 1 && l -> lint != -1) 181 else if (l -> lint2 == 1 && l -> lint != -1)
177 { 182 {
178 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1 + elen; 183 if (l -> lint == 3)
184 l -> len = OPLEN(instab[l -> insn].ops[1]) + 1 + elen;
185 else
186 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1 + elen;
179 } 187 }
180 } 188 }
181 } 189 }
182 190
183 void insn_resolve_gen_aux(asmstate_t *as, line_t *l, int force, int elen) 191 void insn_resolve_gen_aux(asmstate_t *as, line_t *l, int force, int elen)
259 { 267 {
260 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2 + elen; 268 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2 + elen;
261 } 269 }
262 else if (l -> lint2 == 1 && l -> lint != -1) 270 else if (l -> lint2 == 1 && l -> lint != -1)
263 { 271 {
264 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1 + elen; 272 if (l -> lint == 3)
273 l -> len = OPLEN(instab[l -> insn].ops[1]) + 1 + elen;
274 else
275 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1 + elen;
265 } 276 }
266 } 277 }
267 } 278 }
268 279
269 void insn_emit_gen_aux(asmstate_t *as, line_t *l, int extra) 280 void insn_emit_gen_aux(asmstate_t *as, line_t *l, int extra)
276 if (extra != -1) 287 if (extra != -1)
277 lwasm_emit(l, extra); 288 lwasm_emit(l, extra);
278 289
279 if (l -> lint2 == 1) 290 if (l -> lint2 == 1)
280 { 291 {
292 if (l -> lint == 3)
293 {
294 int offs;
295 if (lw_expr_istype(e, lw_expr_type_int))
296 {
297 offs = lw_expr_intval(e);
298 if ((offs >= -16 && offs <= 15) || offs >= 0xFFF0)
299 {
300 l -> pb |= offs & 0x1f;
301 l -> lint = 0;
302 }
303 else
304 {
305 lwasm_register_error(as, l, E_BYTE_OVERFLOW);
306 }
307 }
308 else
309 {
310 lwasm_register_error(as, l, E_EXPRESSION_NOT_RESOLVED);
311 }
312 }
281 lwasm_emit(l, l -> pb); 313 lwasm_emit(l, l -> pb);
282 if (l -> lint > 0) 314 if (l -> lint > 0)
283 { 315 {
284 int i; 316 int i;
285 i = lw_expr_intval(e); 317 i = lw_expr_intval(e);
373 { 405 {
374 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2; 406 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2;
375 } 407 }
376 else if (l -> lint2 == 1 && l -> lint != -1) 408 else if (l -> lint2 == 1 && l -> lint != -1)
377 { 409 {
378 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1; 410 if (l -> lint == 3)
411 l -> len = OPLEN(instab[l -> insn].ops[1]) + 1;
412 else
413 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
379 } 414 }
380 } 415 }
381 } 416 }
382 417
383 RESOLVEFUNC(insn_resolve_gen8) 418 RESOLVEFUNC(insn_resolve_gen8)
445 { 480 {
446 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2; 481 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2;
447 } 482 }
448 else if (l -> lint2 == 1 && l -> lint != -1) 483 else if (l -> lint2 == 1 && l -> lint != -1)
449 { 484 {
450 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1; 485 if (l -> lint == 3)
486 l -> len = OPLEN(instab[l -> insn].ops[1]) + 1;
487 else
488 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
451 } 489 }
452 } 490 }
453 } 491 }
454 492
455 RESOLVEFUNC(insn_resolve_gen16) 493 RESOLVEFUNC(insn_resolve_gen16)
507 { 545 {
508 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2; 546 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2;
509 } 547 }
510 else if (l -> lint2 == 1 && l -> lint != -1) 548 else if (l -> lint2 == 1 && l -> lint != -1)
511 { 549 {
512 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1; 550 if (l -> lint == 3)
551 l -> len = OPLEN(instab[l -> insn].ops[1]) + 1;
552 else
553 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
513 } 554 }
514 } 555 }
515 } 556 }
516 557
517 RESOLVEFUNC(insn_resolve_gen32) 558 RESOLVEFUNC(insn_resolve_gen32)