8 #include "opcode/rl78.h"
14 RL78_Opcode_Decoded * rl78;
15 int (* getbyte)(void *);
20 #define ID(x) rl78->id = RLO_##x, rl78->lineno = __LINE__
21 #define OP(n,t,r,a) (rl78->op[n].type = t, \
22 rl78->op[n].reg = r, \
23 rl78->op[n].addend = a )
24 #define OPX(n,t,r1,r2,a) \
25 (rl78->op[n].type = t, \
26 rl78->op[n].reg = r1, \
27 rl78->op[n].reg2 = r2, \
28 rl78->op[n].addend = a )
30 #define W() rl78->size = RL78_Word
32 #define AU ATTRIBUTE_UNUSED
33 #define GETBYTE() (ld->op [ld->rl78->n_bytes++] = ld->getbyte (ld->ptr))
34 #define B ((unsigned long) GETBYTE())
36 #define SYNTAX(x) rl78->syntax = x
38 #define UNSUPPORTED() \
39 rl78->syntax = "*unknown*"
41 #define RB(x) ((x)+RL78_Reg_X)
42 #define RW(x) ((x)+RL78_Reg_AX)
44 #define Fz rl78->flags = RL78_PSW_Z
45 #define Fza rl78->flags = RL78_PSW_Z | RL78_PSW_AC
46 #define Fzc rl78->flags = RL78_PSW_Z | RL78_PSW_CY
47 #define Fzac rl78->flags = RL78_PSW_Z | RL78_PSW_AC | RL78_PSW_CY
48 #define Fa rl78->flags = RL78_PSW_AC
49 #define Fc rl78->flags = RL78_PSW_CY
50 #define Fac rl78->flags = RL78_PSW_AC | RL78_PSW_CY
52 #define IMMU(bytes) immediate (bytes, 0, ld)
53 #define IMMS(bytes) immediate (bytes, 1, ld)
56 immediate (int bytes, int sign_extend, LocalData * ld)
64 if (sign_extend && (i & 0x80))
70 if (sign_extend && (i & 0x8000))
77 if (sign_extend && (i & 0x800000))
81 fprintf (stderr, "Programmer error: immediate() called with invalid byte count %d\n", bytes);
87 #define DC(c) OP (0, RL78_Operand_Immediate, 0, c)
88 #define DR(r) OP (0, RL78_Operand_Register, RL78_Reg_##r, 0)
89 #define DRB(r) OP (0, RL78_Operand_Register, RB(r), 0)
90 #define DRW(r) OP (0, RL78_Operand_Register, RW(r), 0)
91 #define DM(r,a) OP (0, RL78_Operand_Indirect, RL78_Reg_##r, a)
92 #define DM2(r1,r2,a) OPX (0, RL78_Operand_Indirect, RL78_Reg_##r1, RL78_Reg_##r2, a)
93 #define DE() rl78->op[0].use_es = 1
94 #define DB(b) set_bit (rl78->op, b)
95 #define DCY() DR(PSW); DB(0)
96 #define DPUSH() OP (0, RL78_Operand_PreDec, RL78_Reg_SP, 0);
98 #define SC(c) OP (1, RL78_Operand_Immediate, 0, c)
99 #define SR(r) OP (1, RL78_Operand_Register, RL78_Reg_##r, 0)
100 #define SRB(r) OP (1, RL78_Operand_Register, RB(r), 0)
101 #define SRW(r) OP (1, RL78_Operand_Register, RW(r), 0)
102 #define SM(r,a) OP (1, RL78_Operand_Indirect, RL78_Reg_##r, a)
103 #define SM2(r1,r2,a) OPX (1, RL78_Operand_Indirect, RL78_Reg_##r1, RL78_Reg_##r2, a)
104 #define SE() rl78->op[1].use_es = 1
105 #define SB(b) set_bit (rl78->op+1, b)
106 #define SCY() SR(PSW); SB(0)
107 #define COND(c) rl78->op[1].condition = RL78_Condition_##c
108 #define SPOP() OP (1, RL78_Operand_PostInc, RL78_Reg_SP, 0);
111 set_bit (RL78_Opcode_Operand *op, int bit)
113 op->bit_number = bit;
115 case RL78_Operand_Register:
116 op->type = RL78_Operand_Bit;
118 case RL78_Operand_Indirect:
119 op->type = RL78_Operand_BitIndirect;
140 #define SADDR saddr (IMMU (1))
141 #define SFR sfr (IMMU (1))
144 rl78_decode_opcode (unsigned long pc AU,
145 RL78_Opcode_Decoded * rl78,
146 int (* getbyte)(void *),
149 LocalData lds, * ld = &lds;
150 unsigned char op_buf[20] = {0};
151 unsigned char *op = op_buf;
155 lds.getbyte = getbyte;
159 memset (rl78, 0, sizeof (*rl78));
163 /* Byte registers, not including A. */
164 /** VARY rba 000 010 011 100 101 110 111 */
165 /* Word registers, not including AX. */
166 /** VARY ra 01 10 11 */
168 /*----------------------------------------------------------------------*/
177 /*----------------------------------------------------------------------*/
179 /** 0000 1111 add %0, %e1%!1 */
180 ID(add); DR(A); SM(None, IMMU(2)); Fzac;
182 /** 0000 1101 add %0, %e1%1 */
183 ID(add); DR(A); SM(HL, 0); Fzac;
185 /** 0110 0001 1000 000 add %0, %e1%1 */
186 ID(add); DR(A); SM2(HL, B, 0); Fzac;
188 /** 0000 1110 add %0, %e1%1 */
189 ID(add); DR(A); SM(HL, IMMU(1)); Fzac;
191 /** 0110 0001 1000 0010 add %0, %e1%1 */
192 ID(add); DR(A); SM2(HL, C, 0); Fzac;
194 /** 0000 1100 add %0, #%1 */
195 ID(add); DR(A); SC(IMMU(1)); Fzac;
197 /** 0110 0001 0000 1rba add %0, %1 */
198 ID(add); DR(A); SRB(rba); Fzac;
200 /** 0000 1011 add %0, %1 */
201 ID(add); DR(A); SM(None, SADDR); Fzac;
203 /** 0110 0001 0000 0reg add %0, %1 */
204 ID(add); DRB(reg); SR(A); Fzac;
206 /** 0000 1010 add %0, #%1 */
207 ID(add); DM(None, SADDR); SC(IMMU(1)); Fzac;
209 /*----------------------------------------------------------------------*/
211 /** 0001 1111 addc %0, %e1%!1 */
212 ID(addc); DR(A); SM(None, IMMU(2)); Fzac;
214 /** 0001 1101 addc %0, %e1%1 */
215 ID(addc); DR(A); SM(HL, 0); Fzac;
217 /** 0110 0001 1001 0000 addc %0, %e1%1 */
218 ID(addc); DR(A); SM2(HL, B, 0); Fzac;
220 /** 0110 0001 1001 0010 addc %0, %e1%1 */
221 ID(addc); DR(A); SM2(HL, C, 0); Fzac;
223 /** 0001 1110 addc %0, %e1%1 */
224 ID(addc); DR(A); SM(HL, IMMU(1)); Fzac;
226 /** 0001 1100 addc %0, #%1 */
227 ID(addc); DR(A); SC(IMMU(1)); Fzac;
229 /** 0110 0001 0001 1rba addc %0, %1 */
230 ID(addc); DR(A); SRB(rba); Fzac;
232 /** 0110 0001 0001 0reg addc %0, %1 */
233 ID(addc); DRB(reg); SR(A); Fzac;
235 /** 0001 1011 addc %0, %1 */
236 ID(addc); DR(A); SM(None, SADDR); Fzac;
238 /** 0001 1010 addc %0, #%1 */
239 ID(addc); DM(None, SADDR); SC(IMMU(1)); Fzac;
241 /*----------------------------------------------------------------------*/
243 /** 0000 0010 addw %0, %e1%!1 */
244 ID(add); W(); DR(AX); SM(None, IMMU(2)); Fzac;
246 /** 0110 0001 0000 1001 addw %0, %e1%1 */
247 ID(add); W(); DR(AX); SM(HL, IMMU(1)); Fzac;
249 /** 0000 0100 addw %0, #%1 */
250 ID(add); W(); DR(AX); SC(IMMU(2)); Fzac;
252 /** 0000 0rw1 addw %0, %1 */
253 ID(add); W(); DR(AX); SRW(rw); Fzac;
255 /** 0000 0110 addw %0, %1 */
256 ID(add); W(); DR(AX); SM(None, SADDR); Fzac;
258 /** 0001 0000 addw %0, #%1 */
259 ID(add); W(); DR(SP); SC(IMMU(1)); Fzac;
261 /*----------------------------------------------------------------------*/
263 /** 0101 1111 and %0, %e1%!1 */
264 ID(and); DR(A); SM(None, IMMU(2)); Fz;
266 /** 0101 1101 and %0, %e1%1 */
267 ID(and); DR(A); SM(HL, 0); Fz;
269 /** 0110 0001 1101 0000 and %0, %e1%1 */
270 ID(and); DR(A); SM2(HL, B, 0); Fz;
272 /** 0101 1110 and %0, %e1%1 */
273 ID(and); DR(A); SM(HL, IMMU(1)); Fz;
275 /** 0110 0001 1101 0010 and %0, %e1%1 */
276 ID(and); DR(A); SM2(HL, C, 0); Fz;
278 /** 0101 1100 and %0, #%1 */
279 ID(and); DR(A); SC(IMMU(1)); Fz;
281 /** 0110 0001 0101 1rba and %0, %1 */
282 ID(and); DR(A); SRB(rba); Fz;
284 /** 0110 0001 0101 0reg and %0, %1 */
285 ID(and); DRB(reg); SR(A); Fz;
287 /** 0101 1011 and %0, %1 */
288 ID(and); DR(A); SM(None, SADDR); Fz;
290 /** 0101 1010 and %0, #%1 */
291 ID(and); DM(None, SADDR); SC(IMMU(1)); Fz;
293 /*----------------------------------------------------------------------*/
295 /** 0111 0001 1bit 0101 and1 cy, %e1%1 */
296 ID(and); DCY(); SM(HL, 0); SB(bit);
298 /** 0111 0001 1bit 1101 and1 cy, %1 */
299 ID(and); DCY(); SR(A); SB(bit);
301 /** 0111 0001 0bit 1101 and1 cy, %s1 */
302 ID(and); DCY(); SM(None, SFR); SB(bit);
304 /** 0111 0001 0bit 0101 and1 cy, %s1 */
305 ID(and); DCY(); SM(None, SADDR); SB(bit);
307 /*----------------------------------------------------------------------*/
309 /* Note that the branch insns need to be listed before the shift
310 ones, as "shift count of zero" means "branch insn" */
312 /** 1101 1100 bc $%a0 */
313 ID(branch_cond); DC(pc+IMMS(1)+2); SR(None); COND(C);
315 /** 1101 1110 bnc $%a0 */
316 ID(branch_cond); DC(pc+IMMS(1)+2); SR(None); COND(NC);
318 /** 0110 0001 1100 0011 bh $%a0 */
319 ID(branch_cond); DC(pc+IMMS(1)+3); SR(None); COND(H);
321 /** 0110 0001 1101 0011 bnh $%a0 */
322 ID(branch_cond); DC(pc+IMMS(1)+3); SR(None); COND(NH);
324 /** 1101 1101 bz $%a0 */
325 ID(branch_cond); DC(pc+IMMS(1)+2); SR(None); COND(Z);
327 /** 1101 1111 bnz $%a0 */
328 ID(branch_cond); DC(pc+IMMS(1)+2); SR(None); COND(NZ);
330 /*----------------------------------------------------------------------*/
332 /** 0011 0001 1bit 0101 bf %e1%1, $%a0 */
333 ID(branch_cond); DC(pc+IMMS(1)+3); SM(HL,0); SB(bit); COND(F);
335 /** 0011 0001 0bit 0101 bf %1, $%a0 */
336 ID(branch_cond); DC(pc+IMMS(1)+3); SR(A); SB(bit); COND(F);
338 /** 0011 0001 1bit 0100 bf %s1, $%a0 */
339 ID(branch_cond); SM(None, SFR); SB(bit); DC(pc+IMMS(1)+4); COND(F);
341 /** 0011 0001 0bit 0100 bf %s1, $%a0 */
342 ID(branch_cond); SM(None, SADDR); SB(bit); DC(pc+IMMS(1)+4); COND(F);
344 /*----------------------------------------------------------------------*/
346 /** 1110 1100 br !%!a0 */
347 ID(branch); DC(IMMU(3));
349 /** 1110 1101 br %!a0 */
350 ID(branch); DC(IMMU(2));
352 /** 1110 1110 br $%!a0 */
353 ID(branch); DC(pc+IMMS(2)+3);
355 /** 1110 1111 br $%a0 */
356 ID(branch); DC(pc+IMMS(1)+2);
358 /** 0110 0001 1100 1011 br ax */
361 /*----------------------------------------------------------------------*/
363 /** 1111 1111 brk1 */
366 /** 0110 0001 1100 1100 brk */
369 /*----------------------------------------------------------------------*/
371 /** 0011 0001 1bit 0011 bt %e1%1, $%a0 */
372 ID(branch_cond); DC(pc+IMMS(1)+3); SM(HL,0); SB(bit); COND(T);
374 /** 0011 0001 0bit 0011 bt %1, $%a0 */
375 ID(branch_cond); DC(pc+IMMS(1)+3); SR(A); SB(bit); COND(T);
377 /** 0011 0001 1bit 0010 bt %s1, $%a0 */
378 ID(branch_cond); SM(None, SFR); SB(bit); DC(pc+IMMS(1)+4); COND(T);
380 /** 0011 0001 0bit 0010 bt %s1, $%a0 */
381 ID(branch_cond); SM(None, SADDR); SB(bit); DC(pc+IMMS(1)+4); COND(T);
383 /*----------------------------------------------------------------------*/
385 /** 0011 0001 1bit 0001 btclr %e1%1, $%a0 */
386 ID(branch_cond_clear); DC(pc+IMMS(1)+3); SM(HL,0); SB(bit); COND(T);
388 /** 0011 0001 0bit 0001 btclr %1, $%a0 */
389 ID(branch_cond_clear); DC(pc+IMMS(1)+3); SR(A); SB(bit); COND(T);
391 /** 0011 0001 1bit 0000 btclr %s1, $%a0 */
392 ID(branch_cond_clear); SM(None, SFR); SB(bit); DC(pc+IMMS(1)+4); COND(T);
394 /** 0011 0001 0bit 0000 btclr %s1, $%a0 */
395 ID(branch_cond_clear); SM(None, SADDR); SB(bit); DC(pc+IMMS(1)+4); COND(T);
397 /*----------------------------------------------------------------------*/
399 /** 1111 1100 call !%!a0 */
400 ID(call); DC(IMMU(3));
402 /** 1111 1101 call %!a0 */
403 ID(call); DC(IMMU(2));
405 /** 1111 1110 call $%!a0 */
406 ID(call); DC(pc+IMMS(2)+3);
408 /** 0110 0001 11rg 1010 call %0 */
411 /** 0110 0001 1nnn 01mm callt [%x0] */
412 ID(call); DM(None, 0x80 + mm*16 + nnn*2);
414 /*----------------------------------------------------------------------*/
416 /** 0111 0001 0bit 1000 clr1 %e0%!0 */
417 ID(mov); DM(None, IMMU(2)); DB(bit); SC(0);
419 /** 0111 0001 1bit 0011 clr1 %e0%0 */
420 ID(mov); DM(HL, 0); DB(bit); SC(0);
422 /** 0111 0001 1bit 1011 clr1 %0 */
423 ID(mov); DR(A); DB(bit); SC(0);
425 /** 0111 0001 1000 1000 clr1 cy */
426 ID(mov); DCY(); SC(0);
428 /** 0111 0001 0bit 1011 clr1 %s0 */
430 ID(mov); DM(None, op0); DB(bit); SC(0);
431 if (op0 == RL78_SFR_PSW && bit == 7)
434 /** 0111 0001 0bit 0011 clr1 %0 */
435 ID(mov); DM(None, SADDR); DB(bit); SC(0);
437 /*----------------------------------------------------------------------*/
439 /** 1111 0101 clrb %e0%!0 */
440 ID(mov); DM(None, IMMU(2)); SC(0);
442 /** 1111 00rg clrb %0 */
443 ID(mov); DRB(rg); SC(0);
445 /** 1111 0100 clrb %0 */
446 ID(mov); DM(None, SADDR); SC(0);
448 /*----------------------------------------------------------------------*/
450 /** 1111 0110 clrw %0 */
451 ID(mov); DR(AX); SC(0);
453 /** 1111 0111 clrw %0 */
454 ID(mov); DR(BC); SC(0);
456 /*----------------------------------------------------------------------*/
458 /** 0100 0000 cmp %e0%!0, #%1 */
459 ID(cmp); DM(None, IMMU(2)); SC(IMMU(1)); Fzac;
461 /** 0100 1010 cmp %0, #%1 */
462 ID(cmp); DM(None, SADDR); SC(IMMU(1)); Fzac;
464 /** 0100 1111 cmp %0, %e1%!1 */
465 ID(cmp); DR(A); SM(None, IMMU(2)); Fzac;
467 /** 0100 1101 cmp %0, %e1%1 */
468 ID(cmp); DR(A); SM(HL, 0); Fzac;
470 /** 0110 0001 1100 0000 cmp %0, %e1%1 */
471 ID(cmp); DR(A); SM2(HL, B, 0); Fzac;
473 /** 0110 0001 1100 0010 cmp %0, %e1%1 */
474 ID(cmp); DR(A); SM2(HL, C, 0); Fzac;
476 /** 0100 1110 cmp %0, %e1%1 */
477 ID(cmp); DR(A); SM(HL, IMMU(1)); Fzac;
479 /** 0100 1100 cmp %0, #%1 */
480 ID(cmp); DR(A); SC(IMMU(1)); Fzac;
482 /** 0110 0001 0100 1rba cmp %0, %1 */
483 ID(cmp); DR(A); SRB(rba); Fzac;
485 /** 0110 0001 0100 0reg cmp %0, %1 */
486 ID(cmp); DRB(reg); SR(A); Fzac;
488 /** 0100 1011 cmp %0, %1 */
489 ID(cmp); DR(A); SM(None, SADDR); Fzac;
491 /*----------------------------------------------------------------------*/
493 /** 1101 0101 cmp0 %e0%!0 */
494 ID(cmp); DM(None, IMMU(2)); SC(0); Fzac;
496 /** 1101 00rg cmp0 %0 */
497 ID(cmp); DRB(rg); SC(0); Fzac;
499 /** 1101 0100 cmp0 %0 */
500 ID(cmp); DM(None, SADDR); SC(0); Fzac;
502 /*----------------------------------------------------------------------*/
504 /** 0110 0001 1101 1110 cmps %0, %e1%1 */
505 ID(cmp); DR(X); SM(HL, IMMU(1)); Fzac;
507 /*----------------------------------------------------------------------*/
509 /** 0100 0010 cmpw %0, %e1%!1 */
510 ID(cmp); W(); DR(AX); SM(None, IMMU(2)); Fzac;
512 /** 0110 0001 0100 1001 cmpw %0, %e1%1 */
513 ID(cmp); W(); DR(AX); SM(HL, IMMU(1)); Fzac;
515 /** 0100 0100 cmpw %0, #%1 */
516 ID(cmp); W(); DR(AX); SC(IMMU(2)); Fzac;
518 /** 0100 0ra1 cmpw %0, %1 */
519 ID(cmp); W(); DR(AX); SRW(ra); Fzac;
521 /** 0100 0110 cmpw %0, %1 */
522 ID(cmp); W(); DR(AX); SM(None, SADDR); Fzac;
524 /*----------------------------------------------------------------------*/
526 /** 1011 0000 dec %e0%!0 */
527 ID(sub); DM(None, IMMU(2)); SC(1); Fza;
529 /** 0110 0001 0110 1001 dec %e0%0 */
530 ID(sub); DM(HL, IMMU(1)); SC(1); Fza;
532 /** 1001 0reg dec %0 */
533 ID(sub); DRB(reg); SC(1); Fza;
535 /** 1011 0100 dec %0 */
536 ID(sub); DM(None, SADDR); SC(1); Fza;
538 /*----------------------------------------------------------------------*/
540 /** 1011 0010 decw %e0%!0 */
541 ID(sub); W(); DM(None, IMMU(2)); SC(1);
543 /** 0110 0001 1000 1001 decw %e0%0 */
544 ID(sub); W(); DM(HL, IMMU(1)); SC(1);
546 /** 1011 0rg1 decw %0 */
547 ID(sub); W(); DRW(rg); SC(1);
549 /** 1011 0110 decw %0 */
550 ID(sub); W(); DM(None, SADDR); SC(1);
552 /*----------------------------------------------------------------------*/
554 /** 0110 0001 1110 1101 halt */
557 /*----------------------------------------------------------------------*/
559 /** 1010 0000 inc %e0%!0 */
560 ID(add); DM(None, IMMU(2)); SC(1); Fza;
562 /** 0110 0001 0101 1001 inc %e0%0 */
563 ID(add); DM(HL, IMMU(1)); SC(1); Fza;
565 /** 1000 0reg inc %0 */
566 ID(add); DRB(reg); SC(1); Fza;
568 /** 1010 0100 inc %0 */
569 ID(add); DM(None, SADDR); SC(1); Fza;
571 /*----------------------------------------------------------------------*/
573 /** 1010 0010 incw %e0%!0 */
574 ID(add); W(); DM(None, IMMU(2)); SC(1);
576 /** 0110 0001 0111 1001 incw %e0%0 */
577 ID(add); W(); DM(HL, IMMU(1)); SC(1);
579 /** 1010 0rg1 incw %0 */
580 ID(add); W(); DRW(rg); SC(1);
582 /** 1010 0110 incw %0 */
583 ID(add); W(); DM(None, SADDR); SC(1);
585 /*----------------------------------------------------------------------*/
587 /** 1100 1111 mov %e0%!0, #%1 */
588 ID(mov); DM(None, IMMU(2)); SC(IMMU(1));
590 /** 1001 1111 mov %e0%!0, %1 */
591 ID(mov); DM(None, IMMU(2)); SR(A);
593 /** 1001 1001 mov %e0%0,%1 */
594 ID(mov); DM(DE, 0); SR(A);
596 /** 1100 1010 mov %e0%0, #%1 */
597 ID(mov); DM(DE, IMMU(1)); SC(IMMU(1));
599 /** 1001 1010 mov %e0%0, %1 */
600 ID(mov); DM(DE, IMMU(1)); SR(A);
602 /** 1001 1011 mov %e0%0,%1 */
603 ID(mov); DM(HL, 0); SR(A);
605 /** 0110 0001 1101 1001 mov %e0%0, %1 */
606 ID(mov); DM2(HL, B, 0); SR(A);
608 /** 1100 1100 mov %e0%0, #%1 */
609 ID(mov); DM(HL, IMMU(1)); SC(IMMU(1));
611 /** 1001 1100 mov %e0%0, %1 */
612 ID(mov); DM(HL, IMMU(1)); SR(A);
614 /** 0110 0001 1111 1001 mov %e0%0, %1 */
615 ID(mov); DM2(HL, C, 0); SR(A);
617 /** 1100 1000 mov %0, #%1 */
618 ID(mov); DM(SP, IMMU(1)); SC(IMMU(1));
620 /** 1001 1000 mov %0, %1 */
621 ID(mov); DM(SP, IMMU(1)); SR(A);
623 /** 1000 1111 mov %0, %e1%!1 */
624 ID(mov); DR(A); SM(None, IMMU(2));
626 /** 1000 1001 mov %0, %e1%1 */
627 ID(mov); DR(A); SM(DE, 0);
629 /** 1000 1010 mov %0, %e1%1 */
630 ID(mov); DR(A); SM(DE, IMMU(1));
632 /** 1000 1011 mov %0, %e1%1 */
633 ID(mov); DR(A); SM(HL, 0);
635 /** 1000 1100 mov %0, %e1%1 */
636 ID(mov); DR(A); SM(HL, IMMU(1));
638 /** 0110 0001 1100 1001 mov %0, %e1%1 */
639 ID(mov); DR(A); SM2(HL, B, 0);
641 /** 0110 0001 1110 1001 mov %0, %e1%1 */
642 ID(mov); DR(A); SM2(HL, C, 0);
644 /** 1000 1000 mov %0, %e1%1 */
645 ID(mov); DR(A); SM(SP, IMMU(1));
647 /** 0101 0reg mov %0, #%1 */
648 ID(mov); DRB(reg); SC(IMMU(1));
650 /** 0110 0rba mov %0, %1 */
651 ID(mov); DR(A); SRB(rba);
653 /** 1000 1110 1111 1101 mov %0, %1 */
654 ID(mov); DR(A); SR(ES);
656 /** 0000 1001 mov %0, %e1%1 */
657 ID(mov); DR(A); SM(B, IMMU(2));
659 /** 0100 1001 mov %0, %e1%1 */
660 ID(mov); DR(A); SM(BC, IMMU(2));
662 /** 0010 1001 mov %0, %e1%1 */
663 ID(mov); DR(A); SM(C, IMMU(2));
665 /** 1000 1110 mov %0, %s1 */
666 ID(mov); DR(A); SM(None, SFR);
668 /** 1000 1101 mov %0, %1 */
669 ID(mov); DR(A); SM(None, SADDR);
671 /** 1110 1001 mov %0, %e1%!1 */
672 ID(mov); DR(B); SM(None, IMMU(2));
674 /** 0111 0rba mov %0, %1 */
675 ID(mov); DRB(rba); SR(A);
677 /** 1110 1000 mov %0, %1 */
678 ID(mov); DR(B); SM(None, SADDR);
680 /** 1111 1001 mov %0, %e1%!1 */
681 ID(mov); DR(C); SM(None, IMMU(2));
683 /** 1111 1000 mov %0, %1 */
684 ID(mov); DR(C); SM(None, SADDR);
686 /** 1101 1001 mov %0, %e1%!1 */
687 ID(mov); DR(X); SM(None, IMMU(2));
689 /** 1101 1000 mov %0, %1 */
690 ID(mov); DR(X); SM(None, SADDR);
692 /** 1001 1110 1111 1100 mov %0, %1 */
693 ID(mov); DR(CS); SR(A);
695 /** 0100 0001 mov %0, #%1 */
696 ID(mov); DR(ES); SC(IMMU(1));
698 /** 1001 1110 1111 1101 mov %0, %1 */
699 ID(mov); DR(ES); SR(A);
701 /** 0110 0001 1011 1000 mov %0, %1 */
702 ID(mov); DR(ES); SM(None, SADDR);
704 /** 0001 1001 mov %e0%0, #%1 */
705 ID(mov); DM(B, IMMU(2)); SC(IMMU(1));
707 /** 0001 1000 mov %e0%0, %1 */
708 ID(mov); DM(B, IMMU(2)); SR(A);
710 /** 0011 1001 mov %e0%0, #%1 */
711 ID(mov); DM(BC, IMMU(2)); SC(IMMU(1));
713 /** 0100 1000 mov %e0%0, %1 */
714 ID(mov); DM(BC, IMMU(2)); SR(A);
716 /** 0011 1000 mov %e0%0, #%1 */
717 ID(mov); DM(C, IMMU(2)); SC(IMMU(1));
719 /** 0010 1000 mov %e0%0, %1 */
720 ID(mov); DM(C, IMMU(2)); SR(A);
722 /** 1100 1101 mov %0, #%1 */
723 ID(mov); DM(None, SADDR); SC(IMMU(1));
725 /** 1001 1101 mov %0, %1 */
726 ID(mov); DM(None, SADDR); SR(A);
728 /** 1100 1110 mov %s0, #%1 */
731 ID(mov); DM(None, op0); SC(op1);
736 rl78->syntax = "mulhu"; ID(mulhu);
739 rl78->syntax = "mulh"; ID(mulh);
742 rl78->syntax = "divhu"; ID(divhu);
745 rl78->syntax = "divwu"; ID(divwu);
748 rl78->syntax = "machu"; ID(machu);
751 rl78->syntax = "mach"; ID(mach);
755 /** 1001 1110 mov %0, %1 */
756 ID(mov); DM(None, SFR); SR(A);
758 /*----------------------------------------------------------------------*/
760 /** 0111 0001 1bit 0001 mov1 %e0%0, cy */
761 ID(mov); DM(HL, 0); DB(bit); SCY();
763 /** 0111 0001 1bit 1001 mov1 %e0%0, cy */
764 ID(mov); DR(A); DB(bit); SCY();
766 /** 0111 0001 1bit 0100 mov1 cy, %e1%1 */
767 ID(mov); DCY(); SM(HL, 0); SB(bit);
769 /** 0111 0001 1bit 1100 mov1 cy, %e1%1 */
770 ID(mov); DCY(); SR(A); SB(bit);
772 /** 0111 0001 0bit 0100 mov1 cy, %1 */
773 ID(mov); DCY(); SM(None, SADDR); SB(bit);
775 /** 0111 0001 0bit 1100 mov1 cy, %s1 */
776 ID(mov); DCY(); SM(None, SFR); SB(bit);
778 /** 0111 0001 0bit 0001 mov1 %0, cy */
779 ID(mov); DM(None, SADDR); DB(bit); SCY();
781 /** 0111 0001 0bit 1001 mov1 %s0, cy */
782 ID(mov); DM(None, SFR); DB(bit); SCY();
784 /*----------------------------------------------------------------------*/
786 /** 0110 0001 1100 1110 movs %e0%0, %1 */
787 ID(mov); DM(HL, IMMU(1)); SR(X); Fzc;
789 /*----------------------------------------------------------------------*/
791 /** 1011 1111 movw %e0%!0, %1 */
792 ID(mov); W(); DM(None, IMMU(2)); SR(AX);
794 /** 1011 1001 movw %e0%0, %1 */
795 ID(mov); W(); DM(DE, 0); SR(AX);
797 /** 1011 1010 movw %e0%0, %1 */
798 ID(mov); W(); DM(DE, IMMU(1)); SR(AX);
800 /** 1011 1011 movw %e0%0, %1 */
801 ID(mov); W(); DM(HL, 0); SR(AX);
803 /** 1011 1100 movw %e0%0, %1 */
804 ID(mov); W(); DM(HL, IMMU(1)); SR(AX);
806 /** 1011 1000 movw %0, %1 */
807 ID(mov); W(); DM(SP, IMMU(1)); SR(AX);
809 /** 1010 1111 movw %0, %e1%!1 */
810 ID(mov); W(); DR(AX); SM(None, IMMU(2));
813 /** 1010 1001 movw %0, %e1%1 */
814 ID(mov); W(); DR(AX); SM(DE, 0);
816 /** 1010 1010 movw %0, %e1%1 */
817 ID(mov); W(); DR(AX); SM(DE, IMMU(1));
819 /** 1010 1011 movw %0, %e1%1 */
820 ID(mov); W(); DR(AX); SM(HL, 0);
822 /** 1010 1100 movw %0, %e1%1 */
823 ID(mov); W(); DR(AX); SM(HL, IMMU(1));
825 /** 1010 1000 movw %0, %1 */
826 ID(mov); W(); DR(AX); SM(SP, IMMU(1));
828 /** 0011 0rg0 movw %0, #%1 */
829 ID(mov); W(); DRW(rg); SC(IMMU(2));
831 /** 0001 0ra1 movw %0, %1 */
832 ID(mov); W(); DR(AX); SRW(ra);
834 /** 0001 0ra0 movw %0, %1 */
835 ID(mov); W(); DRW(ra); SR(AX);
837 /** 0101 1001 movw %0, %e1%1 */
838 ID(mov); W(); DR(AX); SM(B, IMMU(2));
840 /** 0110 1001 movw %0, %e1%1 */
841 ID(mov); W(); DR(AX); SM(C, IMMU(2));
843 /** 0111 1001 movw %0, %e1%1 */
844 ID(mov); W(); DR(AX); SM(BC, IMMU(2));
846 /** 0101 1000 movw %e0%0, %1 */
847 ID(mov); W(); DM(B, IMMU(2)); SR(AX);
849 /** 0110 1000 movw %e0%0, %1 */
850 ID(mov); W(); DM(C, IMMU(2)); SR(AX);
852 /** 0111 1000 movw %e0%0, %1 */
853 ID(mov); W(); DM(BC, IMMU(2)); SR(AX);
855 /** 1010 1101 movw %0, %1 */
856 ID(mov); W(); DR(AX); SM(None, SADDR);
858 /** 1010 1110 movw %0, %s1 */
859 ID(mov); W(); DR(AX); SM(None, SFR);
861 /** 11ra 1011 movw %0, %e1%!1 */
862 ID(mov); W(); DRW(ra); SM(None, IMMU(2));
864 /** 11ra 1010 movw %0, %1 */
865 ID(mov); W(); DRW(ra); SM(None, SADDR);
867 /** 1100 1001 movw %0, #%1 */
868 ID(mov); W(); DM(None, SADDR); SC(IMMU(2));
870 /** 1011 1101 movw %0, %1 */
871 ID(mov); W(); DM(None, SADDR); SR(AX);
873 /** 1100 1011 movw %0, #%1 */
874 ID(mov); W(); DM(None, SFR); SC(IMMU(2));
876 /** 1011 1110 movw %0, %1 */
877 ID(mov); W(); DM(None, SFR); SR(AX);
879 /*----------------------------------------------------------------------*/
881 /** 1101 0110 mulu x */
884 /*----------------------------------------------------------------------*/
889 /*----------------------------------------------------------------------*/
891 /** 1110 0101 oneb %e0%!0 */
892 ID(mov); DM(None, IMMU(2)); SC(1);
894 /** 1110 00rg oneb %0 */
895 ID(mov); DRB(rg); SC(1);
897 /** 1110 0100 oneb %0 */
898 ID(mov); DM(None, SADDR); SC(1);
900 /*----------------------------------------------------------------------*/
902 /** 1110 0110 onew %0 */
903 ID(mov); DR(AX); SC(1);
905 /** 1110 0111 onew %0 */
906 ID(mov); DR(BC); SC(1);
908 /*----------------------------------------------------------------------*/
910 /** 0110 1111 or %0, %e1%!1 */
911 ID(or); DR(A); SM(None, IMMU(2)); Fz;
913 /** 0110 1101 or %0, %e1%1 */
914 ID(or); DR(A); SM(HL, 0); Fz;
916 /** 0110 0001 1110 0000 or %0, %e1%1 */
917 ID(or); DR(A); SM2(HL, B, 0); Fz;
919 /** 0110 1110 or %0, %e1%1 */
920 ID(or); DR(A); SM(HL, IMMU(1)); Fz;
922 /** 0110 0001 1110 0010 or %0, %e1%1 */
923 ID(or); DR(A); SM2(HL, C, 0); Fz;
925 /** 0110 1100 or %0, #%1 */
926 ID(or); DR(A); SC(IMMU(1)); Fz;
928 /** 0110 0001 0110 1rba or %0, %1 */
929 ID(or); DR(A); SRB(rba); Fz;
931 /** 0110 0001 0110 0reg or %0, %1 */
932 ID(or); DRB(reg); SR(A); Fz;
934 /** 0110 1011 or %0, %1 */
935 ID(or); DR(A); SM(None, SADDR); Fz;
937 /** 0110 1010 or %0, #%1 */
938 ID(or); DM(None, SADDR); SC(IMMU(1)); Fz;
940 /*----------------------------------------------------------------------*/
942 /** 0111 0001 1bit 0110 or1 cy, %e1%1 */
943 ID(or); DCY(); SM(HL, 0); SB(bit);
945 /** 0111 0001 1bit 1110 or1 cy, %1 */
946 ID(or); DCY(); SR(A); SB(bit);
948 /** 0111 0001 0bit 1110 or1 cy, %s1 */
949 ID(or); DCY(); SM(None, SFR); SB(bit);
951 /** 0111 0001 0bit 0110 or1 cy, %s1 */
952 ID(or); DCY(); SM(None, SADDR); SB(bit);
954 /*----------------------------------------------------------------------*/
956 /** 1100 0rg0 pop %0 */
957 ID(mov); W(); DRW(rg); SPOP();
959 /** 0110 0001 1100 1101 pop %s0 */
960 ID(mov); W(); DR(PSW); SPOP();
962 /*----------------------------------------------------------------------*/
964 /** 1100 0rg1 push %1 */
965 ID(mov); W(); DPUSH(); SRW(rg);
967 /** 0110 0001 1101 1101 push %s1 */
968 ID(mov); W(); DPUSH(); SR(PSW);
970 /*----------------------------------------------------------------------*/
975 /** 0110 0001 1111 1100 reti */
978 /** 0110 0001 1110 1100 retb */
981 /*----------------------------------------------------------------------*/
983 /** 0110 0001 1110 1011 rol %0, %1 */
984 ID(rol); DR(A); SC(1);
986 /** 0110 0001 1101 1100 rolc %0, %1 */
987 ID(rolc); DR(A); SC(1);
989 /** 0110 0001 111r 1110 rolwc %0, %1 */
990 ID(rolc); W(); DRW(r); SC(1);
992 /** 0110 0001 1101 1011 ror %0, %1 */
993 ID(ror); DR(A); SC(1);
995 /** 0110 0001 1111 1011 rorc %0, %1 */
996 ID(rorc); DR(A); SC(1);
998 /*----------------------------------------------------------------------*/
1000 /* Note that the branch insns need to be listed before the shift
1001 ones, as "shift count of zero" means "branch insn" */
1003 /** 0011 0001 0cnt 1011 sar %0, %1 */
1004 ID(sar); DR(A); SC(cnt);
1006 /** 0011 0001 wcnt 1111 sarw %0, %1 */
1007 ID(sar); W(); DR(AX); SC(wcnt);
1009 /*----------------------------------------------------------------------*/
1011 /** 0110 0001 11rb 1111 sel rb%1 */
1014 /*----------------------------------------------------------------------*/
1016 /** 0111 0001 0bit 0000 set1 %e0%!0 */
1017 ID(mov); DM(None, IMMU(2)); DB(bit); SC(1);
1019 /** 0111 0001 1bit 0010 set1 %e0%0 */
1020 ID(mov); DM(HL, 0); DB(bit); SC(1);
1022 /** 0111 0001 1bit 1010 set1 %0 */
1023 ID(mov); DR(A); DB(bit); SC(1);
1025 /** 0111 0001 1000 0000 set1 cy */
1026 ID(mov); DCY(); SC(1);
1028 /** 0111 0001 0bit 1010 set1 %s0 */
1030 ID(mov); DM(None, op0); DB(bit); SC(1);
1031 if (op0 == RL78_SFR_PSW && bit == 7)
1032 rl78->syntax = "ei";
1034 /** 0111 0001 0bit 0010 set1 %0 */
1035 ID(mov); DM(None, SADDR); DB(bit); SC(1);
1037 /*----------------------------------------------------------------------*/
1039 /** 0011 0001 0cnt 1001 shl %0, %1 */
1040 ID(shl); DR(A); SC(cnt);
1042 /** 0011 0001 0cnt 1000 shl %0, %1 */
1043 ID(shl); DR(B); SC(cnt);
1045 /** 0011 0001 0cnt 0111 shl %0, %1 */
1046 ID(shl); DR(C); SC(cnt);
1048 /** 0011 0001 wcnt 1101 shlw %0, %1 */
1049 ID(shl); W(); DR(AX); SC(wcnt);
1051 /** 0011 0001 wcnt 1100 shlw %0, %1 */
1052 ID(shl); W(); DR(BC); SC(wcnt);
1054 /*----------------------------------------------------------------------*/
1056 /** 0011 0001 0cnt 1010 shr %0, %1 */
1057 ID(shr); DR(A); SC(cnt);
1059 /** 0011 0001 wcnt 1110 shrw %0, %1 */
1060 ID(shr); W(); DR(AX); SC(wcnt);
1062 /*----------------------------------------------------------------------*/
1064 /** 0110 0001 1100 1000 sk%c1 */
1067 /** 0110 0001 1110 0011 sk%c1 */
1070 /** 0110 0001 1101 1000 sk%c1 */
1073 /** 0110 0001 1111 0011 sk%c1 */
1076 /** 0110 0001 1111 1000 sk%c1 */
1079 /** 0110 0001 1110 1000 sk%c1 */
1082 /*----------------------------------------------------------------------*/
1084 /** 0110 0001 1111 1101 stop */
1087 /*----------------------------------------------------------------------*/
1089 /** 0010 1111 sub %0, %e1%!1 */
1090 ID(sub); DR(A); SM(None, IMMU(2)); Fzac;
1092 /** 0010 1101 sub %0, %e1%1 */
1093 ID(sub); DR(A); SM(HL, 0); Fzac;
1095 /** 0110 0001 1010 000 sub %0, %e1%1 */
1096 ID(sub); DR(A); SM2(HL, B, 0); Fzac;
1098 /** 0010 1110 sub %0, %e1%1 */
1099 ID(sub); DR(A); SM(HL, IMMU(1)); Fzac;
1101 /** 0110 0001 1010 0010 sub %0, %e1%1 */
1102 ID(sub); DR(A); SM2(HL, C, 0); Fzac;
1104 /** 0010 1100 sub %0, #%1 */
1105 ID(sub); DR(A); SC(IMMU(1)); Fzac;
1107 /** 0110 0001 0010 1rba sub %0, %1 */
1108 ID(sub); DR(A); SRB(rba); Fzac;
1110 /** 0010 1011 sub %0, %1 */
1111 ID(sub); DR(A); SM(None, SADDR); Fzac;
1113 /** 0110 0001 0010 0reg sub %0, %1 */
1114 ID(sub); DRB(reg); SR(A); Fzac;
1116 /** 0010 1010 sub %0, #%1 */
1117 ID(sub); DM(None, SADDR); SC(IMMU(1)); Fzac;
1119 /*----------------------------------------------------------------------*/
1121 /** 0011 1111 subc %0, %e1%!1 */
1122 ID(subc); DR(A); SM(None, IMMU(2)); Fzac;
1124 /** 0011 1101 subc %0, %e1%1 */
1125 ID(subc); DR(A); SM(HL, 0); Fzac;
1127 /** 0110 0001 1011 0000 subc %0, %e1%1 */
1128 ID(subc); DR(A); SM2(HL, B, 0); Fzac;
1130 /** 0110 0001 1011 0010 subc %0, %e1%1 */
1131 ID(subc); DR(A); SM2(HL, C, 0); Fzac;
1133 /** 0011 1110 subc %0, %e1%1 */
1134 ID(subc); DR(A); SM(HL, IMMU(1)); Fzac;
1136 /** 0011 1100 subc %0, #%1 */
1137 ID(subc); DR(A); SC(IMMU(1)); Fzac;
1139 /** 0110 0001 0011 1rba subc %0, %1 */
1140 ID(subc); DR(A); SRB(rba); Fzac;
1142 /** 0110 0001 0011 0reg subc %0, %1 */
1143 ID(subc); DRB(reg); SR(A); Fzac;
1145 /** 0011 1011 subc %0, %1 */
1146 ID(subc); DR(A); SM(None, SADDR); Fzac;
1148 /** 0011 1010 subc %0, #%1 */
1149 ID(subc); DM(None, SADDR); SC(IMMU(1)); Fzac;
1151 /*----------------------------------------------------------------------*/
1153 /** 0010 0010 subw %0, %e1%!1 */
1154 ID(sub); W(); DR(AX); SM(None, IMMU(2)); Fzac;
1156 /** 0110 0001 0010 1001 subw %0, %e1%1 */
1157 ID(sub); W(); DR(AX); SM(HL, IMMU(1)); Fzac;
1159 /** 0010 0100 subw %0, #%1 */
1160 ID(sub); W(); DR(AX); SC(IMMU(2)); Fzac;
1162 /** 0010 0rw1 subw %0, %1 */
1163 ID(sub); W(); DR(AX); SRW(rw); Fzac;
1165 /** 0010 0110 subw %0, %1 */
1166 ID(sub); W(); DR(AX); SM(None, SADDR); Fzac;
1168 /** 0010 0000 subw %0, #%1 */
1169 ID(sub); W(); DR(SP); SC(IMMU(1)); Fzac;
1171 /*----------------------------------------------------------------------*/
1173 /** 0110 0001 1010 1010 xch %0, %e1%!1 */
1174 ID(xch); DR(A); SM(None, IMMU(2));
1176 /** 0110 0001 1010 1110 xch %0, %e1%1 */
1177 ID(xch); DR(A); SM(DE, 0);
1179 /** 0110 0001 1010 1111 xch %0, %e1%1 */
1180 ID(xch); DR(A); SM(DE, IMMU(1));
1182 /** 0110 0001 1010 1100 xch %0, %e1%1 */
1183 ID(xch); DR(A); SM(HL, 0);
1185 /** 0110 0001 1011 1001 xch %0, %e1%1 */
1186 ID(xch); DR(A); SM2(HL, B, 0);
1188 /** 0110 0001 1010 1101 xch %0, %e1%1 */
1189 ID(xch); DR(A); SM(HL, IMMU(1));
1191 /** 0110 0001 1010 1001 xch %0, %e1%1 */
1192 ID(xch); DR(A); SM2(HL, C, 0);
1194 /** 0110 0001 1000 1reg xch %0, %1 */
1195 /* Note: DECW uses reg == X, so this must follow DECW */
1196 ID(xch); DR(A); SRB(reg);
1198 /** 0110 0001 1010 1000 xch %0, %1 */
1199 ID(xch); DR(A); SM(None, SADDR);
1201 /** 0110 0001 1010 1011 xch %0, %1 */
1202 ID(xch); DR(A); SM(None, SFR);
1204 /** 0000 1000 xch a, x */
1205 ID(xch); DR(A); SR(X);
1207 /*----------------------------------------------------------------------*/
1209 /** 0011 0ra1 xchw %0, %1 */
1210 ID(xch); W(); DR(AX); SRW(ra);
1212 /*----------------------------------------------------------------------*/
1214 /** 0111 1111 xor %0, %e1%!1 */
1215 ID(xor); DR(A); SM(None, IMMU(2)); Fz;
1217 /** 0111 1101 xor %0, %e1%1 */
1218 ID(xor); DR(A); SM(HL, 0); Fz;
1220 /** 0110 0001 1111 0000 xor %0, %e1%1 */
1221 ID(xor); DR(A); SM2(HL, B, 0); Fz;
1223 /** 0111 1110 xor %0, %e1%1 */
1224 ID(xor); DR(A); SM(HL, IMMU(1)); Fz;
1226 /** 0110 0001 1111 0010 xor %0, %e1%1 */
1227 ID(xor); DR(A); SM2(HL, C, 0); Fz;
1229 /** 0111 1100 xor %0, #%1 */
1230 ID(xor); DR(A); SC(IMMU(1)); Fz;
1232 /** 0110 0001 0111 1rba xor %0, %1 */
1233 ID(xor); DR(A); SRB(rba); Fz;
1235 /** 0110 0001 0111 0reg xor %0, %1 */
1236 ID(xor); DRB(reg); SR(A); Fz;
1238 /** 0111 1011 xor %0, %1 */
1239 ID(xor); DR(A); SM(None, SADDR); Fz;
1241 /** 0111 1010 xor %0, #%1 */
1242 ID(xor); DM(None, SADDR); SC(IMMU(1)); Fz;
1244 /*----------------------------------------------------------------------*/
1246 /** 0111 0001 1bit 0111 xor1 cy, %e1%1 */
1247 ID(xor); DCY(); SM(HL, 0); SB(bit);
1249 /** 0111 0001 1bit 1111 xor1 cy, %1 */
1250 ID(xor); DCY(); SR(A); SB(bit);
1252 /** 0111 0001 0bit 1111 xor1 cy, %s1 */
1253 ID(xor); DCY(); SM(None, SFR); SB(bit);
1255 /** 0111 0001 0bit 0111 xor1 cy, %s1 */
1256 ID(xor); DCY(); SM(None, SADDR); SB(bit);
1258 /*----------------------------------------------------------------------*/
1262 return rl78->n_bytes;