2 /* Copyright (C) 2012-2017 Free Software Foundation, Inc.
3 Contributed by Red Hat.
6 This file is part of the GNU opcodes library.
8 This library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 It is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
28 #include "opcode/rl78.h"
34 RL78_Opcode_Decoded * rl78;
35 int (* getbyte)(void *);
40 #define ID(x) rl78->id = RLO_##x, rl78->lineno = __LINE__
41 #define OP(n,t,r,a) (rl78->op[n].type = t, \
42 rl78->op[n].reg = r, \
43 rl78->op[n].addend = a )
44 #define OPX(n,t,r1,r2,a) \
45 (rl78->op[n].type = t, \
46 rl78->op[n].reg = r1, \
47 rl78->op[n].reg2 = r2, \
48 rl78->op[n].addend = a )
50 #define W() rl78->size = RL78_Word
52 #define AU ATTRIBUTE_UNUSED
55 #define GETBYTE() (ld->rl78->n_bytes < (OP_BUF_LEN - 1) ? ld->op [ld->rl78->n_bytes++] = ld->getbyte (ld->ptr): 0)
56 #define B ((unsigned long) GETBYTE())
58 #define SYNTAX(x) rl78->syntax = x
60 #define UNSUPPORTED() \
61 rl78->syntax = "*unknown*"
63 #define RB(x) ((x)+RL78_Reg_X)
64 #define RW(x) ((x)+RL78_Reg_AX)
66 #define Fz rl78->flags = RL78_PSW_Z
67 #define Fza rl78->flags = RL78_PSW_Z | RL78_PSW_AC
68 #define Fzc rl78->flags = RL78_PSW_Z | RL78_PSW_CY
69 #define Fzac rl78->flags = RL78_PSW_Z | RL78_PSW_AC | RL78_PSW_CY
70 #define Fa rl78->flags = RL78_PSW_AC
71 #define Fc rl78->flags = RL78_PSW_CY
72 #define Fac rl78->flags = RL78_PSW_AC | RL78_PSW_CY
74 #define IMMU(bytes) immediate (bytes, 0, ld)
75 #define IMMS(bytes) immediate (bytes, 1, ld)
78 immediate (int bytes, int sign_extend, LocalData * ld)
86 if (sign_extend && (i & 0x80))
92 if (sign_extend && (i & 0x8000))
99 if (sign_extend && (i & 0x800000))
103 fprintf (stderr, "Programmer error: immediate() called with invalid byte count %d\n", bytes);
109 #define DC(c) OP (0, RL78_Operand_Immediate, 0, c)
110 #define DR(r) OP (0, RL78_Operand_Register, RL78_Reg_##r, 0)
111 #define DRB(r) OP (0, RL78_Operand_Register, RB(r), 0)
112 #define DRW(r) OP (0, RL78_Operand_Register, RW(r), 0)
113 #define DM(r,a) OP (0, RL78_Operand_Indirect, RL78_Reg_##r, a)
114 #define DM2(r1,r2,a) OPX (0, RL78_Operand_Indirect, RL78_Reg_##r1, RL78_Reg_##r2, a)
115 #define DE() rl78->op[0].use_es = 1
116 #define DB(b) set_bit (rl78->op, b)
117 #define DCY() DR(PSW); DB(0)
118 #define DPUSH() OP (0, RL78_Operand_PreDec, RL78_Reg_SP, 0);
120 #define SC(c) OP (1, RL78_Operand_Immediate, 0, c)
121 #define SR(r) OP (1, RL78_Operand_Register, RL78_Reg_##r, 0)
122 #define SRB(r) OP (1, RL78_Operand_Register, RB(r), 0)
123 #define SRW(r) OP (1, RL78_Operand_Register, RW(r), 0)
124 #define SM(r,a) OP (1, RL78_Operand_Indirect, RL78_Reg_##r, a)
125 #define SM2(r1,r2,a) OPX (1, RL78_Operand_Indirect, RL78_Reg_##r1, RL78_Reg_##r2, a)
126 #define SE() rl78->op[1].use_es = 1
127 #define SB(b) set_bit (rl78->op+1, b)
128 #define SCY() SR(PSW); SB(0)
129 #define COND(c) rl78->op[1].condition = RL78_Condition_##c
130 #define SPOP() OP (1, RL78_Operand_PostInc, RL78_Reg_SP, 0);
133 set_bit (RL78_Opcode_Operand *op, int bit)
135 op->bit_number = bit;
137 case RL78_Operand_Register:
138 op->type = RL78_Operand_Bit;
140 case RL78_Operand_Indirect:
141 op->type = RL78_Operand_BitIndirect;
162 #define SADDR saddr (IMMU (1))
163 #define SFR sfr (IMMU (1))
166 rl78_decode_opcode (unsigned long pc AU,
167 RL78_Opcode_Decoded * rl78,
168 int (* getbyte)(void *),
172 LocalData lds, * ld = &lds;
173 unsigned char op_buf[OP_BUF_LEN] = {0};
174 unsigned char *op = op_buf;
178 lds.getbyte = getbyte;
182 memset (rl78, 0, sizeof (*rl78));
186 /* Byte registers, not including A. */
187 /** VARY rba 000 010 011 100 101 110 111 */
188 /* Word registers, not including AX. */
189 /** VARY ra 01 10 11 */
191 /*----------------------------------------------------------------------*/
200 /*----------------------------------------------------------------------*/
202 /** 0000 1111 add %0, %e!1 */
203 ID(add); DR(A); SM(None, IMMU(2)); Fzac;
205 /** 0000 1101 add %0, %e1 */
206 ID(add); DR(A); SM(HL, 0); Fzac;
208 /** 0110 0001 1000 000 add %0, %e1 */
209 ID(add); DR(A); SM2(HL, B, 0); Fzac;
211 /** 0000 1110 add %0, %ea1 */
212 ID(add); DR(A); SM(HL, IMMU(1)); Fzac;
214 /** 0110 0001 1000 0010 add %0, %e1 */
215 ID(add); DR(A); SM2(HL, C, 0); Fzac;
217 /** 0000 1100 add %0, #%1 */
218 ID(add); DR(A); SC(IMMU(1)); Fzac;
220 /** 0110 0001 0000 1rba add %0, %1 */
221 ID(add); DR(A); SRB(rba); Fzac;
223 /** 0000 1011 add %0, %1 */
224 ID(add); DR(A); SM(None, SADDR); Fzac;
226 /** 0110 0001 0000 0reg add %0, %1 */
227 ID(add); DRB(reg); SR(A); Fzac;
229 /** 0000 1010 add %0, #%1 */
230 ID(add); DM(None, SADDR); SC(IMMU(1)); Fzac;
232 /*----------------------------------------------------------------------*/
234 /** 0001 1111 addc %0, %e!1 */
235 ID(addc); DR(A); SM(None, IMMU(2)); Fzac;
237 /** 0001 1101 addc %0, %e1 */
238 ID(addc); DR(A); SM(HL, 0); Fzac;
240 /** 0110 0001 1001 0000 addc %0, %e1 */
241 ID(addc); DR(A); SM2(HL, B, 0); Fzac;
243 /** 0110 0001 1001 0010 addc %0, %e1 */
244 ID(addc); DR(A); SM2(HL, C, 0); Fzac;
246 /** 0001 1110 addc %0, %ea1 */
247 ID(addc); DR(A); SM(HL, IMMU(1)); Fzac;
249 /** 0001 1100 addc %0, #%1 */
250 ID(addc); DR(A); SC(IMMU(1)); Fzac;
252 /** 0110 0001 0001 1rba addc %0, %1 */
253 ID(addc); DR(A); SRB(rba); Fzac;
255 /** 0110 0001 0001 0reg addc %0, %1 */
256 ID(addc); DRB(reg); SR(A); Fzac;
258 /** 0001 1011 addc %0, %1 */
259 ID(addc); DR(A); SM(None, SADDR); Fzac;
261 /** 0001 1010 addc %0, #%1 */
262 ID(addc); DM(None, SADDR); SC(IMMU(1)); Fzac;
264 /*----------------------------------------------------------------------*/
266 /** 0000 0010 addw %0, %e!1 */
267 ID(add); W(); DR(AX); SM(None, IMMU(2)); Fzac;
269 /** 0110 0001 0000 1001 addw %0, %ea1 */
270 ID(add); W(); DR(AX); SM(HL, IMMU(1)); Fzac;
272 /** 0000 0100 addw %0, #%1 */
273 ID(add); W(); DR(AX); SC(IMMU(2)); Fzac;
275 /** 0000 0rw1 addw %0, %1 */
276 ID(add); W(); DR(AX); SRW(rw); Fzac;
278 /** 0000 0110 addw %0, %1 */
279 ID(add); W(); DR(AX); SM(None, SADDR); Fzac;
281 /** 0001 0000 addw %0, #%1 */
282 ID(add); W(); DR(SP); SC(IMMU(1)); Fzac;
284 /*----------------------------------------------------------------------*/
286 /** 0101 1111 and %0, %e!1 */
287 ID(and); DR(A); SM(None, IMMU(2)); Fz;
289 /** 0101 1101 and %0, %e1 */
290 ID(and); DR(A); SM(HL, 0); Fz;
292 /** 0110 0001 1101 0000 and %0, %e1 */
293 ID(and); DR(A); SM2(HL, B, 0); Fz;
295 /** 0101 1110 and %0, %ea1 */
296 ID(and); DR(A); SM(HL, IMMU(1)); Fz;
298 /** 0110 0001 1101 0010 and %0, %e1 */
299 ID(and); DR(A); SM2(HL, C, 0); Fz;
301 /** 0101 1100 and %0, #%1 */
302 ID(and); DR(A); SC(IMMU(1)); Fz;
304 /** 0110 0001 0101 1rba and %0, %1 */
305 ID(and); DR(A); SRB(rba); Fz;
307 /** 0110 0001 0101 0reg and %0, %1 */
308 ID(and); DRB(reg); SR(A); Fz;
310 /** 0101 1011 and %0, %1 */
311 ID(and); DR(A); SM(None, SADDR); Fz;
313 /** 0101 1010 and %0, #%1 */
314 ID(and); DM(None, SADDR); SC(IMMU(1)); Fz;
316 /*----------------------------------------------------------------------*/
318 /** 0111 0001 1bit 0101 and1 cy, %e1 */
319 ID(and); DCY(); SM(HL, 0); SB(bit);
321 /** 0111 0001 1bit 1101 and1 cy, %1 */
322 ID(and); DCY(); SR(A); SB(bit);
324 /** 0111 0001 0bit 1101 and1 cy, %s1 */
325 ID(and); DCY(); SM(None, SFR); SB(bit);
327 /** 0111 0001 0bit 0101 and1 cy, %s1 */
328 ID(and); DCY(); SM(None, SADDR); SB(bit);
330 /*----------------------------------------------------------------------*/
332 /* Note that the branch insns need to be listed before the shift
333 ones, as "shift count of zero" means "branch insn" */
335 /** 1101 1100 bc $%a0 */
336 ID(branch_cond); DC(pc+IMMS(1)+2); SR(None); COND(C);
338 /** 1101 1110 bnc $%a0 */
339 ID(branch_cond); DC(pc+IMMS(1)+2); SR(None); COND(NC);
341 /** 0110 0001 1100 0011 bh $%a0 */
342 ID(branch_cond); DC(pc+IMMS(1)+3); SR(None); COND(H);
344 /** 0110 0001 1101 0011 bnh $%a0 */
345 ID(branch_cond); DC(pc+IMMS(1)+3); SR(None); COND(NH);
347 /** 1101 1101 bz $%a0 */
348 ID(branch_cond); DC(pc+IMMS(1)+2); SR(None); COND(Z);
350 /** 1101 1111 bnz $%a0 */
351 ID(branch_cond); DC(pc+IMMS(1)+2); SR(None); COND(NZ);
353 /*----------------------------------------------------------------------*/
355 /** 0011 0001 1bit 0101 bf %e1, $%a0 */
356 ID(branch_cond); DC(pc+IMMS(1)+3); SM(HL,0); SB(bit); COND(F);
358 /** 0011 0001 0bit 0101 bf %1, $%a0 */
359 ID(branch_cond); DC(pc+IMMS(1)+3); SR(A); SB(bit); COND(F);
361 /** 0011 0001 1bit 0100 bf %s1, $%a0 */
362 ID(branch_cond); SM(None, SFR); SB(bit); DC(pc+IMMS(1)+4); COND(F);
364 /** 0011 0001 0bit 0100 bf %s1, $%a0 */
365 ID(branch_cond); SM(None, SADDR); SB(bit); DC(pc+IMMS(1)+4); COND(F);
367 /*----------------------------------------------------------------------*/
369 /** 1110 1100 br !%!a0 */
370 ID(branch); DC(IMMU(3));
372 /** 1110 1101 br %!a0 */
373 ID(branch); DC(IMMU(2));
375 /** 1110 1110 br $%!a0 */
376 ID(branch); DC(pc+IMMS(2)+3);
378 /** 1110 1111 br $%a0 */
379 ID(branch); DC(pc+IMMS(1)+2);
381 /** 0110 0001 1100 1011 br ax */
384 /*----------------------------------------------------------------------*/
386 /** 1111 1111 brk1 */
389 /** 0110 0001 1100 1100 brk */
392 /*----------------------------------------------------------------------*/
394 /** 0011 0001 1bit 0011 bt %e1, $%a0 */
395 ID(branch_cond); DC(pc+IMMS(1)+3); SM(HL,0); SB(bit); COND(T);
397 /** 0011 0001 0bit 0011 bt %1, $%a0 */
398 ID(branch_cond); DC(pc+IMMS(1)+3); SR(A); SB(bit); COND(T);
400 /** 0011 0001 1bit 0010 bt %s1, $%a0 */
401 ID(branch_cond); SM(None, SFR); SB(bit); DC(pc+IMMS(1)+4); COND(T);
403 /** 0011 0001 0bit 0010 bt %s1, $%a0 */
404 ID(branch_cond); SM(None, SADDR); SB(bit); DC(pc+IMMS(1)+4); COND(T);
406 /*----------------------------------------------------------------------*/
408 /** 0011 0001 1bit 0001 btclr %e1, $%a0 */
409 ID(branch_cond_clear); DC(pc+IMMS(1)+3); SM(HL,0); SB(bit); COND(T);
411 /** 0011 0001 0bit 0001 btclr %1, $%a0 */
412 ID(branch_cond_clear); DC(pc+IMMS(1)+3); SR(A); SB(bit); COND(T);
414 /** 0011 0001 1bit 0000 btclr %s1, $%a0 */
415 ID(branch_cond_clear); SM(None, SFR); SB(bit); DC(pc+IMMS(1)+4); COND(T);
417 /** 0011 0001 0bit 0000 btclr %s1, $%a0 */
418 ID(branch_cond_clear); SM(None, SADDR); SB(bit); DC(pc+IMMS(1)+4); COND(T);
420 /*----------------------------------------------------------------------*/
422 /** 1111 1100 call !%!a0 */
423 ID(call); DC(IMMU(3));
425 /** 1111 1101 call %!a0 */
426 ID(call); DC(IMMU(2));
428 /** 1111 1110 call $%!a0 */
429 ID(call); DC(pc+IMMS(2)+3);
431 /** 0110 0001 11rg 1010 call %0 */
434 /** 0110 0001 1nnn 01mm callt [%x0] */
435 ID(call); DM(None, 0x80 + mm*16 + nnn*2);
437 /*----------------------------------------------------------------------*/
439 /** 0111 0001 0bit 1000 clr1 %e!0 */
440 ID(mov); DM(None, IMMU(2)); DB(bit); SC(0);
442 /** 0111 0001 1bit 0011 clr1 %e0 */
443 ID(mov); DM(HL, 0); DB(bit); SC(0);
445 /** 0111 0001 1bit 1011 clr1 %0 */
446 ID(mov); DR(A); DB(bit); SC(0);
448 /** 0111 0001 1000 1000 clr1 cy */
449 ID(mov); DCY(); SC(0);
451 /** 0111 0001 0bit 1011 clr1 %s0 */
453 ID(mov); DM(None, op0); DB(bit); SC(0);
454 if (op0 == RL78_SFR_PSW && bit == 7)
457 /** 0111 0001 0bit 0011 clr1 %0 */
458 ID(mov); DM(None, SADDR); DB(bit); SC(0);
460 /*----------------------------------------------------------------------*/
462 /** 1111 0101 clrb %e!0 */
463 ID(mov); DM(None, IMMU(2)); SC(0);
465 /** 1111 00rg clrb %0 */
466 ID(mov); DRB(rg); SC(0);
468 /** 1111 0100 clrb %0 */
469 ID(mov); DM(None, SADDR); SC(0);
471 /*----------------------------------------------------------------------*/
473 /** 1111 0110 clrw %0 */
474 ID(mov); DR(AX); SC(0);
476 /** 1111 0111 clrw %0 */
477 ID(mov); DR(BC); SC(0);
479 /*----------------------------------------------------------------------*/
481 /** 0100 0000 cmp %e!0, #%1 */
482 ID(cmp); DM(None, IMMU(2)); SC(IMMU(1)); Fzac;
484 /** 0100 1010 cmp %0, #%1 */
485 ID(cmp); DM(None, SADDR); SC(IMMU(1)); Fzac;
487 /** 0100 1111 cmp %0, %e!1 */
488 ID(cmp); DR(A); SM(None, IMMU(2)); Fzac;
490 /** 0100 1101 cmp %0, %e1 */
491 ID(cmp); DR(A); SM(HL, 0); Fzac;
493 /** 0110 0001 1100 0000 cmp %0, %e1 */
494 ID(cmp); DR(A); SM2(HL, B, 0); Fzac;
496 /** 0110 0001 1100 0010 cmp %0, %e1 */
497 ID(cmp); DR(A); SM2(HL, C, 0); Fzac;
499 /** 0100 1110 cmp %0, %ea1 */
500 ID(cmp); DR(A); SM(HL, IMMU(1)); Fzac;
502 /** 0100 1100 cmp %0, #%1 */
503 ID(cmp); DR(A); SC(IMMU(1)); Fzac;
505 /** 0110 0001 0100 1rba cmp %0, %1 */
506 ID(cmp); DR(A); SRB(rba); Fzac;
508 /** 0110 0001 0100 0reg cmp %0, %1 */
509 ID(cmp); DRB(reg); SR(A); Fzac;
511 /** 0100 1011 cmp %0, %1 */
512 ID(cmp); DR(A); SM(None, SADDR); Fzac;
514 /*----------------------------------------------------------------------*/
516 /** 1101 0101 cmp0 %e!0 */
517 ID(cmp); DM(None, IMMU(2)); SC(0); Fzac;
519 /** 1101 00rg cmp0 %0 */
520 ID(cmp); DRB(rg); SC(0); Fzac;
522 /** 1101 0100 cmp0 %0 */
523 ID(cmp); DM(None, SADDR); SC(0); Fzac;
525 /*----------------------------------------------------------------------*/
527 /** 0110 0001 1101 1110 cmps %0, %ea1 */
528 ID(cmp); DR(X); SM(HL, IMMU(1)); Fzac;
530 /*----------------------------------------------------------------------*/
532 /** 0100 0010 cmpw %0, %e!1 */
533 ID(cmp); W(); DR(AX); SM(None, IMMU(2)); Fzac;
535 /** 0110 0001 0100 1001 cmpw %0, %ea1 */
536 ID(cmp); W(); DR(AX); SM(HL, IMMU(1)); Fzac;
538 /** 0100 0100 cmpw %0, #%1 */
539 ID(cmp); W(); DR(AX); SC(IMMU(2)); Fzac;
541 /** 0100 0ra1 cmpw %0, %1 */
542 ID(cmp); W(); DR(AX); SRW(ra); Fzac;
544 /** 0100 0110 cmpw %0, %1 */
545 ID(cmp); W(); DR(AX); SM(None, SADDR); Fzac;
547 /*----------------------------------------------------------------------*/
549 /** 1011 0000 dec %e!0 */
550 ID(sub); DM(None, IMMU(2)); SC(1); Fza;
552 /** 0110 0001 0110 1001 dec %ea0 */
553 ID(sub); DM(HL, IMMU(1)); SC(1); Fza;
555 /** 1001 0reg dec %0 */
556 ID(sub); DRB(reg); SC(1); Fza;
558 /** 1011 0100 dec %0 */
559 ID(sub); DM(None, SADDR); SC(1); Fza;
561 /*----------------------------------------------------------------------*/
563 /** 1011 0010 decw %e!0 */
564 ID(sub); W(); DM(None, IMMU(2)); SC(1);
566 /** 0110 0001 1000 1001 decw %ea0 */
567 ID(sub); W(); DM(HL, IMMU(1)); SC(1);
569 /** 1011 0rg1 decw %0 */
570 ID(sub); W(); DRW(rg); SC(1);
572 /** 1011 0110 decw %0 */
573 ID(sub); W(); DM(None, SADDR); SC(1);
575 /*----------------------------------------------------------------------*/
577 /** 0110 0001 1110 1101 halt */
580 /*----------------------------------------------------------------------*/
582 /** 1010 0000 inc %e!0 */
583 ID(add); DM(None, IMMU(2)); SC(1); Fza;
585 /** 0110 0001 0101 1001 inc %ea0 */
586 ID(add); DM(HL, IMMU(1)); SC(1); Fza;
588 /** 1000 0reg inc %0 */
589 ID(add); DRB(reg); SC(1); Fza;
591 /** 1010 0100 inc %0 */
592 ID(add); DM(None, SADDR); SC(1); Fza;
594 /*----------------------------------------------------------------------*/
596 /** 1010 0010 incw %e!0 */
597 ID(add); W(); DM(None, IMMU(2)); SC(1);
599 /** 0110 0001 0111 1001 incw %ea0 */
600 ID(add); W(); DM(HL, IMMU(1)); SC(1);
602 /** 1010 0rg1 incw %0 */
603 ID(add); W(); DRW(rg); SC(1);
605 /** 1010 0110 incw %0 */
606 ID(add); W(); DM(None, SADDR); SC(1);
608 /*----------------------------------------------------------------------*/
610 /** 1100 1111 mov %e!0, #%1 */
611 ID(mov); DM(None, IMMU(2)); SC(IMMU(1));
613 /** 1001 1111 mov %e!0, %1 */
614 ID(mov); DM(None, IMMU(2)); SR(A);
616 /** 1001 1001 mov %e0, %1 */
617 ID(mov); DM(DE, 0); SR(A);
619 /** 1100 1010 mov %ea0, #%1 */
620 ID(mov); DM(DE, IMMU(1)); SC(IMMU(1));
622 /** 1001 1010 mov %ea0, %1 */
623 ID(mov); DM(DE, IMMU(1)); SR(A);
625 /** 1001 1011 mov %e0, %1 */
626 ID(mov); DM(HL, 0); SR(A);
628 /** 0110 0001 1101 1001 mov %e0, %1 */
629 ID(mov); DM2(HL, B, 0); SR(A);
631 /** 1100 1100 mov %ea0, #%1 */
632 ID(mov); DM(HL, IMMU(1)); SC(IMMU(1));
634 /** 1001 1100 mov %ea0, %1 */
635 ID(mov); DM(HL, IMMU(1)); SR(A);
637 /** 0110 0001 1111 1001 mov %e0, %1 */
638 ID(mov); DM2(HL, C, 0); SR(A);
640 /** 1100 1000 mov %a0, #%1 */
641 ID(mov); DM(SP, IMMU(1)); SC(IMMU(1));
643 /** 1001 1000 mov %a0, %1 */
644 ID(mov); DM(SP, IMMU(1)); SR(A);
646 /** 1000 1111 mov %0, %e!1 */
647 ID(mov); DR(A); SM(None, IMMU(2));
649 /** 1000 1001 mov %0, %e1 */
650 ID(mov); DR(A); SM(DE, 0);
652 /** 1000 1010 mov %0, %ea1 */
653 ID(mov); DR(A); SM(DE, IMMU(1));
655 /** 1000 1011 mov %0, %e1 */
656 ID(mov); DR(A); SM(HL, 0);
658 /** 1000 1100 mov %0, %ea1 */
659 ID(mov); DR(A); SM(HL, IMMU(1));
661 /** 0110 0001 1100 1001 mov %0, %e1 */
662 ID(mov); DR(A); SM2(HL, B, 0);
664 /** 0110 0001 1110 1001 mov %0, %e1 */
665 ID(mov); DR(A); SM2(HL, C, 0);
667 /** 1000 1000 mov %0, %ea1 */
668 ID(mov); DR(A); SM(SP, IMMU(1));
670 /** 0101 0reg mov %0, #%1 */
671 ID(mov); DRB(reg); SC(IMMU(1));
673 /** 0110 0rba mov %0, %1 */
674 ID(mov); DR(A); SRB(rba);
676 /** 1000 1110 1111 1101 mov %0, %1 */
677 ID(mov); DR(A); SR(ES);
679 /** 0000 1001 mov %0, %e1 */
680 ID(mov); DR(A); SM(B, IMMU(2));
682 /** 0100 1001 mov %0, %e1 */
683 ID(mov); DR(A); SM(BC, IMMU(2));
685 /** 0010 1001 mov %0, %e1 */
686 ID(mov); DR(A); SM(C, IMMU(2));
688 /** 1000 1110 mov %0, %s1 */
689 ID(mov); DR(A); SM(None, SFR);
691 /** 1000 1101 mov %0, %1 */
692 ID(mov); DR(A); SM(None, SADDR);
694 /** 1110 1001 mov %0, %e!1 */
695 ID(mov); DR(B); SM(None, IMMU(2));
697 /** 0111 0rba mov %0, %1 */
698 ID(mov); DRB(rba); SR(A);
700 /** 1110 1000 mov %0, %1 */
701 ID(mov); DR(B); SM(None, SADDR);
703 /** 1111 1001 mov %0, %e!1 */
704 ID(mov); DR(C); SM(None, IMMU(2));
706 /** 1111 1000 mov %0, %1 */
707 ID(mov); DR(C); SM(None, SADDR);
709 /** 1101 1001 mov %0, %e!1 */
710 ID(mov); DR(X); SM(None, IMMU(2));
712 /** 1101 1000 mov %0, %1 */
713 ID(mov); DR(X); SM(None, SADDR);
715 /** 1001 1110 1111 1100 mov %0, %1 */
716 ID(mov); DR(CS); SR(A);
718 /** 0100 0001 mov %0, #%1 */
719 ID(mov); DR(ES); SC(IMMU(1));
721 /** 1001 1110 1111 1101 mov %0, %1 */
722 ID(mov); DR(ES); SR(A);
724 /** 0110 0001 1011 1000 mov %0, %1 */
725 ID(mov); DR(ES); SM(None, SADDR);
727 /** 0001 1001 mov %e0, #%1 */
728 ID(mov); DM(B, IMMU(2)); SC(IMMU(1));
730 /** 0001 1000 mov %e0, %1 */
731 ID(mov); DM(B, IMMU(2)); SR(A);
733 /** 0011 1001 mov %e0, #%1 */
734 ID(mov); DM(BC, IMMU(2)); SC(IMMU(1));
736 /** 0100 1000 mov %e0, %1 */
737 ID(mov); DM(BC, IMMU(2)); SR(A);
739 /** 0011 1000 mov %e0, #%1 */
740 ID(mov); DM(C, IMMU(2)); SC(IMMU(1));
742 /** 0010 1000 mov %e0, %1 */
743 ID(mov); DM(C, IMMU(2)); SR(A);
745 /** 1100 1101 mov %0, #%1 */
746 ID(mov); DM(None, SADDR); SC(IMMU(1));
748 /** 1001 1101 mov %0, %1 */
749 ID(mov); DM(None, SADDR); SR(A);
751 /** 1100 1110 mov %s0, #%1 */
754 ID(mov); DM(None, op0); SC(op1);
755 if (op0 == 0xffffb && isa == RL78_ISA_G14)
759 rl78->syntax = "mulhu"; ID(mulhu);
762 rl78->syntax = "mulh"; ID(mulh);
765 rl78->syntax = "divhu"; ID(divhu);
768 rl78->syntax = "divwu <old-encoding>"; ID(divwu);
771 rl78->syntax = "machu"; ID(machu);
774 rl78->syntax = "mach"; ID(mach);
777 rl78->syntax = "divwu"; ID(divwu);
781 /** 1001 1110 mov %s0, %1 */
782 ID(mov); DM(None, SFR); SR(A);
784 /*----------------------------------------------------------------------*/
786 /** 0111 0001 1bit 0001 mov1 %e0, cy */
787 ID(mov); DM(HL, 0); DB(bit); SCY();
789 /** 0111 0001 1bit 1001 mov1 %e0, cy */
790 ID(mov); DR(A); DB(bit); SCY();
792 /** 0111 0001 1bit 0100 mov1 cy, %e1 */
793 ID(mov); DCY(); SM(HL, 0); SB(bit);
795 /** 0111 0001 1bit 1100 mov1 cy, %e1 */
796 ID(mov); DCY(); SR(A); SB(bit);
798 /** 0111 0001 0bit 0100 mov1 cy, %1 */
799 ID(mov); DCY(); SM(None, SADDR); SB(bit);
801 /** 0111 0001 0bit 1100 mov1 cy, %s1 */
802 ID(mov); DCY(); SM(None, SFR); SB(bit);
804 /** 0111 0001 0bit 0001 mov1 %0, cy */
805 ID(mov); DM(None, SADDR); DB(bit); SCY();
807 /** 0111 0001 0bit 1001 mov1 %s0, cy */
808 ID(mov); DM(None, SFR); DB(bit); SCY();
810 /*----------------------------------------------------------------------*/
812 /** 0110 0001 1100 1110 movs %ea0, %1 */
813 ID(mov); DM(HL, IMMU(1)); SR(X); Fzc;
815 /*----------------------------------------------------------------------*/
817 /** 1011 1111 movw %e!0, %1 */
818 ID(mov); W(); DM(None, IMMU(2)); SR(AX);
820 /** 1011 1001 movw %e0, %1 */
821 ID(mov); W(); DM(DE, 0); SR(AX);
823 /** 1011 1010 movw %ea0, %1 */
824 ID(mov); W(); DM(DE, IMMU(1)); SR(AX);
826 /** 1011 1011 movw %e0, %1 */
827 ID(mov); W(); DM(HL, 0); SR(AX);
829 /** 1011 1100 movw %ea0, %1 */
830 ID(mov); W(); DM(HL, IMMU(1)); SR(AX);
832 /** 1011 1000 movw %a0, %1 */
833 ID(mov); W(); DM(SP, IMMU(1)); SR(AX);
835 /** 1010 1111 movw %0, %e!1 */
836 ID(mov); W(); DR(AX); SM(None, IMMU(2));
839 /** 1010 1001 movw %0, %e1 */
840 ID(mov); W(); DR(AX); SM(DE, 0);
842 /** 1010 1010 movw %0, %ea1 */
843 ID(mov); W(); DR(AX); SM(DE, IMMU(1));
845 /** 1010 1011 movw %0, %e1 */
846 ID(mov); W(); DR(AX); SM(HL, 0);
848 /** 1010 1100 movw %0, %ea1 */
849 ID(mov); W(); DR(AX); SM(HL, IMMU(1));
851 /** 1010 1000 movw %0, %a1 */
852 ID(mov); W(); DR(AX); SM(SP, IMMU(1));
854 /** 0011 0rg0 movw %0, #%1 */
855 ID(mov); W(); DRW(rg); SC(IMMU(2));
857 /** 0001 0ra1 movw %0, %1 */
858 ID(mov); W(); DR(AX); SRW(ra);
860 /** 0001 0ra0 movw %0, %1 */
861 ID(mov); W(); DRW(ra); SR(AX);
863 /** 0101 1001 movw %0, %e1 */
864 ID(mov); W(); DR(AX); SM(B, IMMU(2));
866 /** 0110 1001 movw %0, %e1 */
867 ID(mov); W(); DR(AX); SM(C, IMMU(2));
869 /** 0111 1001 movw %0, %e1 */
870 ID(mov); W(); DR(AX); SM(BC, IMMU(2));
872 /** 0101 1000 movw %e0, %1 */
873 ID(mov); W(); DM(B, IMMU(2)); SR(AX);
875 /** 0110 1000 movw %e0, %1 */
876 ID(mov); W(); DM(C, IMMU(2)); SR(AX);
878 /** 0111 1000 movw %e0, %1 */
879 ID(mov); W(); DM(BC, IMMU(2)); SR(AX);
881 /** 1010 1101 movw %0, %1 */
882 ID(mov); W(); DR(AX); SM(None, SADDR);
884 /** 1010 1110 movw %0, %s1 */
885 ID(mov); W(); DR(AX); SM(None, SFR);
887 /** 11ra 1011 movw %0, %es!1 */
888 ID(mov); W(); DRW(ra); SM(None, IMMU(2));
890 /** 11ra 1010 movw %0, %1 */
891 ID(mov); W(); DRW(ra); SM(None, SADDR);
893 /** 1100 1001 movw %0, #%1 */
894 ID(mov); W(); DM(None, SADDR); SC(IMMU(2));
896 /** 1011 1101 movw %0, %1 */
897 ID(mov); W(); DM(None, SADDR); SR(AX);
899 /** 1100 1011 movw %s0, #%1 */
900 ID(mov); W(); DM(None, SFR); SC(IMMU(2));
902 /** 1011 1110 movw %s0, %1 */
903 ID(mov); W(); DM(None, SFR); SR(AX);
905 /*----------------------------------------------------------------------*/
907 /** 1101 0110 mulu x */
910 /*----------------------------------------------------------------------*/
915 /*----------------------------------------------------------------------*/
917 /** 0111 0001 1100 0000 not1 cy */
918 ID(xor); DCY(); SC(1);
920 /*----------------------------------------------------------------------*/
922 /** 1110 0101 oneb %e!0 */
923 ID(mov); DM(None, IMMU(2)); SC(1);
925 /** 1110 00rg oneb %0 */
926 ID(mov); DRB(rg); SC(1);
928 /** 1110 0100 oneb %0 */
929 ID(mov); DM(None, SADDR); SC(1);
931 /*----------------------------------------------------------------------*/
933 /** 1110 0110 onew %0 */
934 ID(mov); DR(AX); SC(1);
936 /** 1110 0111 onew %0 */
937 ID(mov); DR(BC); SC(1);
939 /*----------------------------------------------------------------------*/
941 /** 0110 1111 or %0, %e!1 */
942 ID(or); DR(A); SM(None, IMMU(2)); Fz;
944 /** 0110 1101 or %0, %e1 */
945 ID(or); DR(A); SM(HL, 0); Fz;
947 /** 0110 0001 1110 0000 or %0, %e1 */
948 ID(or); DR(A); SM2(HL, B, 0); Fz;
950 /** 0110 1110 or %0, %ea1 */
951 ID(or); DR(A); SM(HL, IMMU(1)); Fz;
953 /** 0110 0001 1110 0010 or %0, %e1 */
954 ID(or); DR(A); SM2(HL, C, 0); Fz;
956 /** 0110 1100 or %0, #%1 */
957 ID(or); DR(A); SC(IMMU(1)); Fz;
959 /** 0110 0001 0110 1rba or %0, %1 */
960 ID(or); DR(A); SRB(rba); Fz;
962 /** 0110 0001 0110 0reg or %0, %1 */
963 ID(or); DRB(reg); SR(A); Fz;
965 /** 0110 1011 or %0, %1 */
966 ID(or); DR(A); SM(None, SADDR); Fz;
968 /** 0110 1010 or %0, #%1 */
969 ID(or); DM(None, SADDR); SC(IMMU(1)); Fz;
971 /*----------------------------------------------------------------------*/
973 /** 0111 0001 1bit 0110 or1 cy, %e1 */
974 ID(or); DCY(); SM(HL, 0); SB(bit);
976 /** 0111 0001 1bit 1110 or1 cy, %1 */
977 ID(or); DCY(); SR(A); SB(bit);
979 /** 0111 0001 0bit 1110 or1 cy, %s1 */
980 ID(or); DCY(); SM(None, SFR); SB(bit);
982 /** 0111 0001 0bit 0110 or1 cy, %s1 */
983 ID(or); DCY(); SM(None, SADDR); SB(bit);
985 /*----------------------------------------------------------------------*/
987 /** 1100 0rg0 pop %0 */
988 ID(mov); W(); DRW(rg); SPOP();
990 /** 0110 0001 1100 1101 pop %s0 */
991 ID(mov); W(); DR(PSW); SPOP();
993 /*----------------------------------------------------------------------*/
995 /** 1100 0rg1 push %1 */
996 ID(mov); W(); DPUSH(); SRW(rg);
998 /** 0110 0001 1101 1101 push %s1 */
999 ID(mov); W(); DPUSH(); SR(PSW);
1001 /*----------------------------------------------------------------------*/
1003 /** 1101 0111 ret */
1006 /** 0110 0001 1111 1100 reti */
1009 /** 0110 0001 1110 1100 retb */
1012 /*----------------------------------------------------------------------*/
1014 /** 0110 0001 1110 1011 rol %0, %1 */
1015 ID(rol); DR(A); SC(1);
1017 /** 0110 0001 1101 1100 rolc %0, %1 */
1018 ID(rolc); DR(A); SC(1);
1020 /** 0110 0001 111r 1110 rolwc %0, %1 */
1021 ID(rolc); W(); DRW(r); SC(1);
1023 /** 0110 0001 1101 1011 ror %0, %1 */
1024 ID(ror); DR(A); SC(1);
1026 /** 0110 0001 1111 1011 rorc %0, %1 */
1027 ID(rorc); DR(A); SC(1);
1029 /*----------------------------------------------------------------------*/
1031 /* Note that the branch insns need to be listed before the shift
1032 ones, as "shift count of zero" means "branch insn" */
1034 /** 0011 0001 0cnt 1011 sar %0, %1 */
1035 ID(sar); DR(A); SC(cnt);
1037 /** 0011 0001 wcnt 1111 sarw %0, %1 */
1038 ID(sar); W(); DR(AX); SC(wcnt);
1040 /*----------------------------------------------------------------------*/
1042 /** 0110 0001 11rb 1111 sel rb%1 */
1045 /*----------------------------------------------------------------------*/
1047 /** 0111 0001 0bit 0000 set1 %e!0 */
1048 ID(mov); DM(None, IMMU(2)); DB(bit); SC(1);
1050 /** 0111 0001 1bit 0010 set1 %e0 */
1051 ID(mov); DM(HL, 0); DB(bit); SC(1);
1053 /** 0111 0001 1bit 1010 set1 %0 */
1054 ID(mov); DR(A); DB(bit); SC(1);
1056 /** 0111 0001 1000 0000 set1 cy */
1057 ID(mov); DCY(); SC(1);
1059 /** 0111 0001 0bit 1010 set1 %s0 */
1061 ID(mov); DM(None, op0); DB(bit); SC(1);
1062 if (op0 == RL78_SFR_PSW && bit == 7)
1063 rl78->syntax = "ei";
1065 /** 0111 0001 0bit 0010 set1 %0 */
1066 ID(mov); DM(None, SADDR); DB(bit); SC(1);
1068 /*----------------------------------------------------------------------*/
1070 /** 0011 0001 0cnt 1001 shl %0, %1 */
1071 ID(shl); DR(A); SC(cnt);
1073 /** 0011 0001 0cnt 1000 shl %0, %1 */
1074 ID(shl); DR(B); SC(cnt);
1076 /** 0011 0001 0cnt 0111 shl %0, %1 */
1077 ID(shl); DR(C); SC(cnt);
1079 /** 0011 0001 wcnt 1101 shlw %0, %1 */
1080 ID(shl); W(); DR(AX); SC(wcnt);
1082 /** 0011 0001 wcnt 1100 shlw %0, %1 */
1083 ID(shl); W(); DR(BC); SC(wcnt);
1085 /*----------------------------------------------------------------------*/
1087 /** 0011 0001 0cnt 1010 shr %0, %1 */
1088 ID(shr); DR(A); SC(cnt);
1090 /** 0011 0001 wcnt 1110 shrw %0, %1 */
1091 ID(shr); W(); DR(AX); SC(wcnt);
1093 /*----------------------------------------------------------------------*/
1095 /** 0110 0001 1100 1000 sk%c1 */
1098 /** 0110 0001 1110 0011 sk%c1 */
1101 /** 0110 0001 1101 1000 sk%c1 */
1104 /** 0110 0001 1111 0011 sk%c1 */
1107 /** 0110 0001 1111 1000 sk%c1 */
1110 /** 0110 0001 1110 1000 sk%c1 */
1113 /*----------------------------------------------------------------------*/
1115 /** 0110 0001 1111 1101 stop */
1118 /*----------------------------------------------------------------------*/
1120 /** 0010 1111 sub %0, %e!1 */
1121 ID(sub); DR(A); SM(None, IMMU(2)); Fzac;
1123 /** 0010 1101 sub %0, %e1 */
1124 ID(sub); DR(A); SM(HL, 0); Fzac;
1126 /** 0110 0001 1010 000 sub %0, %e1 */
1127 ID(sub); DR(A); SM2(HL, B, 0); Fzac;
1129 /** 0010 1110 sub %0, %ea1 */
1130 ID(sub); DR(A); SM(HL, IMMU(1)); Fzac;
1132 /** 0110 0001 1010 0010 sub %0, %e1 */
1133 ID(sub); DR(A); SM2(HL, C, 0); Fzac;
1135 /** 0010 1100 sub %0, #%1 */
1136 ID(sub); DR(A); SC(IMMU(1)); Fzac;
1138 /** 0110 0001 0010 1rba sub %0, %1 */
1139 ID(sub); DR(A); SRB(rba); Fzac;
1141 /** 0010 1011 sub %0, %1 */
1142 ID(sub); DR(A); SM(None, SADDR); Fzac;
1144 /** 0110 0001 0010 0reg sub %0, %1 */
1145 ID(sub); DRB(reg); SR(A); Fzac;
1147 /** 0010 1010 sub %0, #%1 */
1148 ID(sub); DM(None, SADDR); SC(IMMU(1)); Fzac;
1150 /*----------------------------------------------------------------------*/
1152 /** 0011 1111 subc %0, %e!1 */
1153 ID(subc); DR(A); SM(None, IMMU(2)); Fzac;
1155 /** 0011 1101 subc %0, %e1 */
1156 ID(subc); DR(A); SM(HL, 0); Fzac;
1158 /** 0110 0001 1011 0000 subc %0, %e1 */
1159 ID(subc); DR(A); SM2(HL, B, 0); Fzac;
1161 /** 0110 0001 1011 0010 subc %0, %e1 */
1162 ID(subc); DR(A); SM2(HL, C, 0); Fzac;
1164 /** 0011 1110 subc %0, %ea1 */
1165 ID(subc); DR(A); SM(HL, IMMU(1)); Fzac;
1167 /** 0011 1100 subc %0, #%1 */
1168 ID(subc); DR(A); SC(IMMU(1)); Fzac;
1170 /** 0110 0001 0011 1rba subc %0, %1 */
1171 ID(subc); DR(A); SRB(rba); Fzac;
1173 /** 0110 0001 0011 0reg subc %0, %1 */
1174 ID(subc); DRB(reg); SR(A); Fzac;
1176 /** 0011 1011 subc %0, %1 */
1177 ID(subc); DR(A); SM(None, SADDR); Fzac;
1179 /** 0011 1010 subc %0, #%1 */
1180 ID(subc); DM(None, SADDR); SC(IMMU(1)); Fzac;
1182 /*----------------------------------------------------------------------*/
1184 /** 0010 0010 subw %0, %e!1 */
1185 ID(sub); W(); DR(AX); SM(None, IMMU(2)); Fzac;
1187 /** 0110 0001 0010 1001 subw %0, %ea1 */
1188 ID(sub); W(); DR(AX); SM(HL, IMMU(1)); Fzac;
1190 /** 0010 0100 subw %0, #%1 */
1191 ID(sub); W(); DR(AX); SC(IMMU(2)); Fzac;
1193 /** 0010 0rw1 subw %0, %1 */
1194 ID(sub); W(); DR(AX); SRW(rw); Fzac;
1196 /** 0010 0110 subw %0, %1 */
1197 ID(sub); W(); DR(AX); SM(None, SADDR); Fzac;
1199 /** 0010 0000 subw %0, #%1 */
1200 ID(sub); W(); DR(SP); SC(IMMU(1)); Fzac;
1202 /*----------------------------------------------------------------------*/
1204 /** 0110 0001 1010 1010 xch %0, %e!1 */
1205 ID(xch); DR(A); SM(None, IMMU(2));
1207 /** 0110 0001 1010 1110 xch %0, %e1 */
1208 ID(xch); DR(A); SM(DE, 0);
1210 /** 0110 0001 1010 1111 xch %0, %ea1 */
1211 ID(xch); DR(A); SM(DE, IMMU(1));
1213 /** 0110 0001 1010 1100 xch %0, %e1 */
1214 ID(xch); DR(A); SM(HL, 0);
1216 /** 0110 0001 1011 1001 xch %0, %e1 */
1217 ID(xch); DR(A); SM2(HL, B, 0);
1219 /** 0110 0001 1010 1101 xch %0, %ea1 */
1220 ID(xch); DR(A); SM(HL, IMMU(1));
1222 /** 0110 0001 1010 1001 xch %0, %e1 */
1223 ID(xch); DR(A); SM2(HL, C, 0);
1225 /** 0110 0001 1000 1reg xch %0, %1 */
1226 /* Note: DECW uses reg == X, so this must follow DECW */
1227 ID(xch); DR(A); SRB(reg);
1229 /** 0110 0001 1010 1000 xch %0, %1 */
1230 ID(xch); DR(A); SM(None, SADDR);
1232 /** 0110 0001 1010 1011 xch %0, %s1 */
1233 ID(xch); DR(A); SM(None, SFR);
1235 /** 0000 1000 xch a, x */
1236 ID(xch); DR(A); SR(X);
1238 /*----------------------------------------------------------------------*/
1240 /** 0011 0ra1 xchw %0, %1 */
1241 ID(xch); W(); DR(AX); SRW(ra);
1243 /*----------------------------------------------------------------------*/
1245 /** 0111 1111 xor %0, %e!1 */
1246 ID(xor); DR(A); SM(None, IMMU(2)); Fz;
1248 /** 0111 1101 xor %0, %e1 */
1249 ID(xor); DR(A); SM(HL, 0); Fz;
1251 /** 0110 0001 1111 0000 xor %0, %e1 */
1252 ID(xor); DR(A); SM2(HL, B, 0); Fz;
1254 /** 0111 1110 xor %0, %ea1 */
1255 ID(xor); DR(A); SM(HL, IMMU(1)); Fz;
1257 /** 0110 0001 1111 0010 xor %0, %e1 */
1258 ID(xor); DR(A); SM2(HL, C, 0); Fz;
1260 /** 0111 1100 xor %0, #%1 */
1261 ID(xor); DR(A); SC(IMMU(1)); Fz;
1263 /** 0110 0001 0111 1rba xor %0, %1 */
1264 ID(xor); DR(A); SRB(rba); Fz;
1266 /** 0110 0001 0111 0reg xor %0, %1 */
1267 ID(xor); DRB(reg); SR(A); Fz;
1269 /** 0111 1011 xor %0, %1 */
1270 ID(xor); DR(A); SM(None, SADDR); Fz;
1272 /** 0111 1010 xor %0, #%1 */
1273 ID(xor); DM(None, SADDR); SC(IMMU(1)); Fz;
1275 /*----------------------------------------------------------------------*/
1277 /** 0111 0001 1bit 0111 xor1 cy, %e1 */
1278 ID(xor); DCY(); SM(HL, 0); SB(bit);
1280 /** 0111 0001 1bit 1111 xor1 cy, %1 */
1281 ID(xor); DCY(); SR(A); SB(bit);
1283 /** 0111 0001 0bit 1111 xor1 cy, %s1 */
1284 ID(xor); DCY(); SM(None, SFR); SB(bit);
1286 /** 0111 0001 0bit 0111 xor1 cy, %s1 */
1287 ID(xor); DCY(); SM(None, SADDR); SB(bit);
1289 /*----------------------------------------------------------------------*/
1293 return rl78->n_bytes;