aboutsummaryrefslogtreecommitdiff
path: root/sim/m32c/m32c.opc
blob: 330bdf254a83ffc859c012763e93d86ce984206d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
/* m32c.opc --- semantics for m32c opcodes.		        -*- mode: c -*-

Copyright (C) 2005, 2007 Free Software Foundation, Inc.
Contributed by Red Hat, Inc.

This file is part of the GNU simulators.

The GNU simulators are free software; you can redistribute them and/or
modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.

The GNU simulators are distributed in the hope that they will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with the GNU simulators; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA  */


#include <stdio.h>
#include <stdlib.h>

#include "cpu.h"
#include "mem.h"
#include "misc.h"
#include "int.h"

#define AU  __attribute__((unused))

#define tprintf if (trace) printf

static unsigned char
getbyte ()
{
  int tsave = trace;
  unsigned char b;

  if (trace == 1)
    trace = 0;
  b = mem_get_pc ();
  regs.r_pc ++;
  trace = tsave;
  return b;
}

#define M32C_ONLY() /* FIXME: add something here */

#define GETBYTE() (op[opi++] = getbyte())

#define UNSUPPORTED() unsupported("unsupported", orig_pc)
#define NOTYET() unsupported("unimplemented", orig_pc)

static void
unsupported (char *tag, int orig_pc)
{
  int i;
  printf("%s opcode at %08x\n", tag, orig_pc);
  regs.r_pc = orig_pc;
  for (i=0; i<2; i++)
    {
      int b = mem_get_pc();
      printf(" %s", bits(b>>4, 4));
      printf(" %s", bits(b, 4));
      regs.r_pc ++;
    }
  printf("\n");
  regs.r_pc = orig_pc;
  for (i=0; i<6; i++)
    {
      printf(" %02x", mem_get_pc ());
      regs.r_pc ++;
    }
  printf("\n");
  exit(1);
}

static int
IMM(int bytes)
{
  int rv = 0;
  switch (bytes)
    {
    case 1:
      rv = mem_get_qi (get_reg(pc));
      break;
    case 2:
      rv = mem_get_hi (get_reg(pc));
      break;
    case 3:
      rv = mem_get_psi (get_reg(pc));
      break;
    case 4:
      rv = mem_get_si (get_reg(pc));
      break;
    }
  regs.r_pc += bytes;
  return rv;
}

#define IMM4() (immm >= 8 ? 7 - immm : immm + 1)

#define NO_PREFIX() PREFIX(0,0,0)

/* Indicate which sorts of prefixes are allowed for the current
   opcode.  */
void
prefix (src_allowed, dest_allowed, index_bytewidth)
{
  /* At the moment, we don't do anything with this information.  We
     just wanted to get the information entered in some
     machine-readable form while we were going through all the
     opcodes.  */
}

#define MATH_OP(dc,s,c,op) \
{ \
  int ma, mb; \
  ma = get_src(dc); \
  mb = s & b2mask[dc.bytes]; \
  ll = (long long)ma op (long long)mb op c; \
  tprintf("0x%x " #op " 0x%x " #op " 0x%x = 0x%llx\n", ma, mb, c, ll); \
  ma = sign_ext (ma, dc.bytes * 8); \
  mb = sign_ext (s, dc.bytes * 8); \
  v = ma op mb op c; \
  tprintf("%d " #op " %d " #op " %d = %d\n", ma, mb, c, v); \
  set_oszc (v, dc.bytes, ll > ((1 op 1) ? b2mask[dc.bytes] : 0)); \
  put_dest (dc, v); \
}

#define LOGIC_OP(dc,s,op) \
{ \
  int ma, mb; \
  ma = get_src(dc); \
  mb = s & b2mask[dc.bytes]; \
  v = ma op mb; \
  tprintf("0x%x " #op " 0x%x = 0x%x\n", ma, mb, v); \
  set_sz (v, dc.bytes); \
  put_dest (dc, v); \
}

#define BIT_OP(dc,bit,expr)                                             \
  b = get_bit2 (dc, bitindex == -1 ? bit : bitindex);                   \
  v = expr;                                                             \
  tprintf ("b=%d, bit=%d, carry=%d, %s = %d\n",                         \
           b,  bitindex == -1 ? bit : bitindex, carry, #expr, v);       \
  put_bit2 (dc,  bitindex == -1 ? bit : bitindex, v);

#define BIT_OPC(dc,bit,expr)                                            \
  b = get_bit2 (dc,  bitindex == -1 ? bit : bitindex);                  \
  v = expr;                                                             \
  tprintf ("b=%d, bit=%d, carry=%d, %s = %d\n",                         \
           b,  bitindex == -1 ? bit : bitindex, carry, #expr, v);       \
  set_c (v);

#define carry (FLAG_C ? 1 : 0)

static void
cmp (int d, int s, int bytes)
{
  int a, b, f=0;
  a = d - s;
  b = sign_ext (d, bytes*8) - sign_ext (s, bytes*8);
  tprintf ("cmp: %x - %x = %08x, %x - %x = %d\n",
	   d, s, a,
	   sign_ext(d,bytes*8), sign_ext(s,bytes*8), b);

  if (b == 0)
    f |= FLAGBIT_Z;
  if (b & b2signbit[bytes])
    f |= FLAGBIT_S;
  if ((d & b2mask[bytes]) >= (s & b2mask[bytes]))
    f |= FLAGBIT_C;
  if (b < b2minsigned[bytes] || b > b2maxsigned[bytes])
    f |= FLAGBIT_O;

  set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O | FLAGBIT_C, f);
}

static void
dadd_op (int ddd, int dd, int sss, int ss, int imm, int add, int cy, int w)
{
  srcdest sc, dc;
  int a, b=0, res;

  prefix (0, 0, 0);

  if (!imm)
    {
      sc = decode_src23 (sss, ss, w+1);
      b = get_src (sc);
    }
  dc = decode_dest23 (ddd, dd, w+1);
  a = get_src (dc);
  if (imm)
    b = IMM(w+1);

  a = bcd2int(a, w);
  b = bcd2int(b, w);

  tprintf("decimal: %d %s %d", a, add?"+":"-", b);
  if (cy)
    tprintf(" c=%d", carry);

  if (add)
    {
      res = a + b;
      if (cy)
	res += carry;
      cy = res > (w ? 9999 : 99);
    }
  else
    {
      res = a - b;
      if (cy)
	res -= (1-carry);
      cy = res >= 0;
      if (res < 0)
	res += w ? 10000 : 100;
    }

  res = int2bcd (res, w);
  tprintf(" = %x\n", res);

  set_szc (res, w+1, cy);

  put_dest (dc, res);
}
#define DADDV(A,C) dadd_op(ddd, dd, sss, ss, 0, A, C, w)
#define DADDI(A,C) dadd_op(ddd, dd, 0, 0, 1, A, C, w)

static void
div_op (int sss, int ss, int u, int x, int bytes)
{
  srcdest sc;
  int s, v, a, b;

  if (sss == -1)
    s = IMM(bytes);
  else
    {
      sc = decode_dest23 (sss, ss, bytes);
      s = get_src (sc);
    }

  v = get_reg (bytes > 1 ? r2r0 : r0);

  if (!u)
    {
      /* FIXME? do we sign extend a0/a1 to .L?  Docs say zero extend.  */
      s = sign_ext (s, bytes*8);
      v = sign_ext (v, bytes*8);
    }

  if (s == 0)
    {
      set_flags (FLAGBIT_O, FLAGBIT_O);
      return;
    }

  if (u)
    {
      a = (unsigned int)v / (unsigned int)s;
      b = (unsigned int)v % (unsigned int)s;
    }
  else
    {
      a = v / s;
      b = v % s;
    }
  if (x)
    {
      if ((s > 0 && b < 0)
	  || (s < 0 && b > 0))
	{
	  a --;
	  b += s;
	}
    }
  tprintf ("%d / %d = %d rem %d\n", v, s, a, b);
  if ((!u && (a > b2maxsigned[bytes]
	      || a < b2minsigned[bytes]))
      || (u && (a > b2mask[bytes])))
    set_flags (FLAGBIT_O, FLAGBIT_O);
  else
    set_flags (FLAGBIT_O, 0);

  switch (bytes)
    {
    case 1:
      put_reg (r0l, a);
      put_reg (r0h, b);
      break;
    case 2:
      put_reg (r0, a);
      put_reg (r2, b);
      break;
    case 4:
      put_reg (r2r0, a);
      break;
    }
}

static void
index_op (int sss, int ss, int do_s, int do_d, int scale, int w)
{
  srcdest sc = decode_src23 (sss, ss, w+1);
  int v = get_src (sc) * scale;
  tprintf("%d = %d * %d, %d %d\n", v, get_src(sc), scale, do_s, do_d);
  decode_index (do_s * v, do_d * v);
}
#define INDEXOP(scale,do_s,do_d)                                \
  index_op (sss, ss, do_s, do_d, scale, w); goto next_opcode

static void
rot_op (srcdest sd, int rotc, int count)
{
  int mask = (sd.bytes == 2) ? 0xffff : 0xff;
  int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
  int v = get_src (sd);
  int c = carry, ct;

  tprintf("%s %x by %d\n", rotc ? "rotc" : "rot", v, count);
  tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
  while (count > 0)
    {
      ct = (v & msb) ? 1 : 0;
      v <<= 1;
      v |= rotc ? c : ct;
      v &= mask;
      c = ct;
      tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
      count --;
    }
  while (count < 0)
    {
      ct = v & 1;
      v >>= 1;
      v |= (rotc ? c : ct) * msb;
      c = ct;
      tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
      count ++;
    }
  put_dest (sd, v);
  set_szc (v, sd.bytes, c);
}

static void
shift_op (srcdest sd, int arith, int count, int setc)
{
  int mask = (sd.bytes == 2) ? 0xffff : 0xff;
  int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
  int v = get_src (sd);
  int c = 0;
  int o = 0;

  if (sd.bytes == 4)
    {
      mask = 0xffffffffU;
      msb = 0x80000000U;
    }

  tprintf("%s %x by %d\n", arith ? "sha" : "shl", v, count);
  tprintf (": %s %d %d\n", bits(v, 8*sd.bytes), c, o);
  while (count > 0)
    {
      c = (v & msb) ? 1 : 0;
      v <<= 1;
      v &= mask;
      if (c != ((v & msb) ? 1 : 0))
	o = 1;
      tprintf (": %s %d %d\n", bits(v, 8*sd.bytes), c, o);
      count --;
    }
  while (count < 0)
    {
      c = v & 1;
      if (arith)
	v = (v & msb) | (v >> 1);
      else
	v = (v >> 1) & (msb - 1);
      tprintf (": %s %d %d\n", bits(v, 8*sd.bytes), c, o);
      count ++;
    }
  put_dest (sd, v);
  set_sz (v, sd.bytes);
  if (setc)
    set_c (c);
  set_flags (FLAGBIT_O, o ? FLAGBIT_O : 0);
}

int
decode_m32c()
{
  unsigned char op[40];
  int opi;
  int orig_pc;
  int v, a, b;
  long long ll;
  srcdest sc, dc;
  int imm;
  int bitindex = -1;
  int t0, t1=0, t2, t3=0;
  int ta0, ta1, dif;

  step_result = M32C_MAKE_STEPPED ();

  decode_indirect (0, 0);
  decode_index (0, 0);

next_opcode:
  opi = 0;
  orig_pc = get_reg (pc);

  tprintf("trace: decode pc = %06x\n", orig_pc);

  /** VARY sss 000 001 010 011 100 */
  /** VARY ddd 000 001 010 011 100 */

  /** 0000 1001				indirect dest */

  decode_indirect (0, 1);
  goto next_opcode;

  /** 0100 0001				indirect src */

  decode_indirect (1, 0);
  goto next_opcode;

  /** 0100 1001				indirect src and dest */

  decode_indirect (1, 1);
  goto next_opcode;

  /** 1010 ddd w dd01 1111		ABS.size dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  v = sign_ext (get_src (dc), w?16:8);
  a = v<0 ? -v : v;
  tprintf("abs(%d) = %d\n", v, a);
  set_osz(a, w+1);
  put_dest (dc, a);

  /** 0000 0001 1000 ddd w dd10 1110	ADC.size #IMM,dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  imm = IMM (w+1);
  MATH_OP (dc, imm, carry, +);

  /** 0000 0001 1sss ddd w dd ss 0100	ADC.size src,dest */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, w+1);
  dc = decode_dest23 (ddd, dd, w+1);
  b = get_src (sc);
  MATH_OP (dc, b, carry, +);

  /** 1011 ddd w dd01 1110		ADCF.size dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  MATH_OP (dc, 0, carry, +);

  /** 1000 ddd w dd10 1110		ADD.size:G #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23(ddd, dd, w+1);
  imm = IMM(w+1);
  MATH_OP (dc, imm, 0, +);

  /** 1000 ddd0 dd11 0001		ADD.L:G #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23(ddd, dd, 4);
  imm = IMM(4);
  MATH_OP (dc, imm, 0, +);

  /** 111L ddd w dd11 immm		ADD.size:Q #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23(ddd, dd, L ? 4 : (w+1));
  imm = sign_ext (immm, 4);
  MATH_OP (dc, imm, 0, +);

  /** 00dd 011w				ADD.size:S #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest2(dd, w+1);
  imm = IMM (w+1);
  MATH_OP (dc, imm, 0, +);

  /** 10i0 110d				ADD.L:S #IMM,A0/A1 */

  prefix (0, 0, 0);
  dc = reg_sd (d ? a1 : a0);
  imm = i ? 2 : 1;
  MATH_OP (dc, imm, 0, +);

  /** 1sss ddd w dd ss 1000		ADD.size:G src,dest */

  prefix (1, 1, 0);
  sc = decode_src23(sss, ss, w+1);
  dc = decode_dest23(ddd, dd, w+1);
  b = get_src (sc);
  MATH_OP (dc, b, 0, +);

  /** 1sss ddd1 dd ss 0010		ADD.L:G src,dest */

  prefix (1, 1, 0);
  sc = decode_src23(sss, ss, 4);
  dc = decode_dest23(ddd, dd, 4);
  b = get_src (sc);
  MATH_OP (dc, b, 0, +);

  /** 1011 0110 0001 0011		ADD.L:G #IMM16,SP */

  prefix (0, 0, 0);
  dc = reg_sd (sp);
  b = sign_ext (IMM(2), 16);
  MATH_OP (dc, b, 0, +);

  /** 01ii 001i				ADD.L:Q #IMM3,SP */

  prefix (0, 0, 0);
  dc = reg_sd (sp);
  b = ii * 2 + i + 1;
  MATH_OP (dc, b, 0, +);

  /** 1011 0110 0000 0011		ADD.L:S #IMM8,SP */

  prefix (0, 0, 0);
  dc = reg_sd (sp);
  b = sign_ext (IMM(1), 8);
  MATH_OP (dc, b, 0, +);

  /** 1000 ddd0 dd01 0001		ADDX #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23(ddd, dd, 4);
  imm = sign_ext (IMM(1), 8);
  MATH_OP (dc, imm, 0, +);

  /** 1sss ddd0 dd ss 0010		ADDX src,dest */

  prefix (1, 1, 0);
  sc = decode_src23(sss, ss, 1);
  dc = decode_dest23(ddd, dd, 4);
  b = sign_ext (get_src (sc), 8);
  MATH_OP (dc, b, 0, +);

  /** 1111 ddd w dd01 immm		ADJNZ.size #IMM,dest,label */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  v = get_src (dc);
  imm = sign_ext(immm, 4);
  tprintf("%d + %d = %d\n", v, imm, v+imm);
  v += imm;
  put_dest (dc, v);
  a = sign_ext (IMM(1), 8);
  if ((v & (w ? 0xffff : 0xff)) != 0)
    {
      tprintf("jmp: %x + 2 + %d = ", get_reg (pc), a);
      put_reg (pc, orig_pc + 2 + a);
      tprintf("%x\n", get_reg (pc));
    }

  /** 1000 ddd w dd11 1111		AND.size:G #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23(ddd, dd, w+1);
  imm = IMM(w+1);
  LOGIC_OP (dc, imm, &);

  /** 01dd 110w				AND.size:S #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest2(dd, w+1);
  imm = IMM (w+1);
  LOGIC_OP (dc, imm, &);

  /** 1sss ddd w dd ss 1101		AND.size:G src,dest */

  prefix (1, 1, 0);
  sc = decode_src23(sss, ss, w+1);
  dc = decode_dest23(ddd, dd, w+1);
  b = get_src (sc);
  LOGIC_OP (dc, b, &);

  /** 0000 0001 1101 sss0 ss00 1bit	BAND src */

  sc = decode_src23 (sss, ss, 1);
  BIT_OPC (sc, bit, b & carry);

  /** 1101 ddd0 dd11 0bit		BCLR dest */

  dc = decode_dest23 (ddd, dd, 1);
  BIT_OP (dc, bit, 0);

  /** 1100 ddd w dd10 1110		BITINDEX.size src */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  bitindex = get_src (dc);
  tprintf ("bitindex set to %d\n", bitindex);
  goto next_opcode;

  /** 1101 ddd0 dd01 0bit		BMcnd dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, 1);
  if (condition_true (IMM (1)))
    put_bit2 (dc, bit, 1);
  else
    put_bit2 (dc, bit, 0);

  /** 1101 1001 0c10 1cnd		BMcnd C */

  prefix (0, 0, 0);
  if (condition_true (c * 8 + cnd))
    set_c (1);
  else
    set_c (0);

  /** 0000 0001 1101 sss0 ss01 1bit	BNAND src */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 1);
  BIT_OPC (sc, bit, !b & carry);

  /** 0000 0001 1101 sss0 ss11 0bit	BNOR src */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 1);
  BIT_OPC (sc, bit, !b | carry);

  /** 1101 ddd0 dd01 1bit		BNOT dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, 1);
  BIT_OP (dc, bit, !b);

  /** 0000 0001 1101 sss0 ss00 0bit	BNTST src */

  prefix (0, 0, 0);
  sc = decode_dest23 (sss, ss, 1);
  b = get_bit2 (sc, bit);
  set_zc (!b, !b);

  /** 0000 0001 1101 sss0 ss11 1bit	BNXOR src */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 1);
  BIT_OPC (sc, bit, !b ^ carry);

  /** 0000 0001 1101 sss0 ss10 0bit	BOR src */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 1);
  BIT_OPC (sc, bit, b | carry);

  /** 0000 0000				BRK */

  /* We report the break to our caller with the PC still pointing at the 
     breakpoint instruction.  */
  put_reg (pc, orig_pc);
  if (verbose)
    printf("[break]\n");
  return M32C_MAKE_HIT_BREAK ();

  /** 0000 1000				BRK */

  if (verbose)
    printf("[break2]\n");
  return M32C_MAKE_HIT_BREAK ();

  /** 1101 ddd0 dd11 1bit		BSET dest */

  dc = decode_dest23 (ddd, dd, 1);
  BIT_OP (dc, bit, 1);

  /** 1101 sss0 ss00 0bit		BTST:G src */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 1);
  b = get_bit2 (sc, bit);
  set_zc (!b, b);

  /** 00bb 101b				BTST:S src */

  sc = decode_src23 (3, 3, 1); /* bit,base:19 */
  b = get_bit2 (sc, bb*2 + b);
  set_zc (!b, b);

  /** 1101 ddd0 dd10 0bit		BTSTC dest */

  prefix (0, 0, 0);
  sc = decode_dest23 (ddd, dd, 1);
  b = get_bit2 (sc, bit);
  set_zc (!b, b);
  put_bit2 (sc, bit, 0);

  /** 1101 ddd0 dd10 1bit		BTSTS dest */

  prefix (0, 0, 0);
  sc = decode_dest23 (ddd, dd, 1);
  b = get_bit2 (sc, bit);
  set_zc (!b, b);
  put_bit2 (sc, bit, 1);

  /** 0000 0001 1101 sss0 ss10 1bit	BXOR src */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 1);
  BIT_OPC (sc, bit, b ^ carry);

  /** 0000 0001 1000 ddd w dd11 1110	CLIP.size #IMM1,#IMM2,dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  a = sign_ext (IMM(w+1), w*8+8);
  b = sign_ext (IMM(w+1), w*8+8);
  v = sign_ext (get_src (dc), w*8+8);
  tprintf("clip %d <= %d <= %d : ", a, v, b);
  if (a > v)
    v = a;
  if (v > b)
    v = b;
  tprintf("%d\n", v);
  put_dest (dc, v);

  /** 1001 ddd w dd10 1110		CMP.size:G #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  v = get_src (dc);
  imm = IMM(w+1);
  cmp (v, imm, w+1);

  /** 1010 ddd0 dd11 0001		CMP.L:G #IMM32,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, 4);
  v = get_src (dc);
  imm = IMM(4);
  cmp (v, imm, 4);

  /** 1110 ddd w dd01 immm		CMP.size:Q #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  v = get_src (dc);
  immm = sign_ext (immm, 4);
  cmp (v, immm, w+1);

  /** 01dd 011w				CMP.size:S #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest2 (dd, w+1);
  v = get_src (dc);
  imm = sign_ext (IMM(w+1),w*8+8);
  cmp (v, imm, w+1);

  /** 1sss ddd w dd ss 0110		CMP.size:G src,dest */

  prefix (1, 1, 0);
  sc = decode_src23 (sss, ss, w+1);
  dc = decode_dest23 (ddd, dd, w+1);
  a = get_src (dc);
  b = get_src (sc);
  cmp (a, b, w+1);

  /** 1sss ddd1 dd ss 0001		CMP.L:G src,dest */

  prefix (1, 1, 0);
  sc = decode_src23 (sss, ss, 4);
  dc = decode_dest23 (ddd, dd, 4);
  a = get_src (dc);
  b = get_src (sc);
  cmp (a, b, 4);

  /** 01dd 000w				CMP.size:S src,R0/R0L */

  prefix (0, 1, 0);
  dc = decode_dest2 (dd, w+1);
  a = get_reg (w ? r0 : r0l);
  b = get_src (dc);
  cmp (a, b, w+1);

  /** 1010 ddd0 dd01 0001		CMPX #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, 4);
  v = get_src (dc);
  imm = sign_ext (IMM(1), 8);
  cmp (v, imm, 4);

  /** 0000 0001 1000 ddd w dd00 1110	DADC.size #IMM,dest */

  DADDI(1,1);

  /** 0000 0001 1sss ddd w dd ss 1000	DADC.size src,dest */

  DADDV(1,1);

  /** 0000 0001 1000 ddd w dd01 1110	DADD.size #IMM,dest */

  DADDI(1,0);

  /** 0000 0001 1sss ddd w dd ss 0000	DADD.size src,dest */

  DADDV(1,0);

  /** 1011 ddd w dd00 1110		DEC.size dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  a = get_src (dc);
  v = a-1;
  tprintf ("%x -- = %x\n", a, v);
  set_sz (v, w+1);
  put_dest (dc, v);

  /** 1011 0000 010w 0011		DIV.size #IMM */

  prefix (0, 0, 0);
  div_op (-1, 0, 0, 0, w+1);

  /** 1000 sss w ss01 1110		DIV.size src */

  prefix (0, 1, 0);
  div_op (sss, ss, 0, 0, w+1);

  /** 0000 0001 1010 sss1 ss01 1111	DIV.L src */

  M32C_ONLY();
  prefix (0, 0, 0);
  div_op (sss, ss, 0, 0, 4);

  /** 1011 0000 000w 0011		DIVU.size #IMM */

  prefix (0, 0, 0);
  div_op (-1, 0, 1, 0, w+1);

  /** 1000 sss w ss00 1110		DIVU.size src */

  prefix (0, 1, 0);
  div_op (sss, ss, 1, 0, w+1);

  /** 0000 0001 1010 sss1 ss00 1111	DIVU.L src */

  M32C_ONLY();
  prefix (0, 0, 0);
  div_op (sss, ss, 1, 0, 4);

  /** 1011 0010 010w 0011		DIVX.size #IMM */

  prefix (0, 0, 0);
  div_op (-1, 0, 0, 1, w+1);

  /** 1001 sss w ss01 1110		DIVX.size src */

  prefix (0, 1, 0);
  div_op (sss, ss, 0, 1, w+1);

  /** 0000 0001 1010 sss1 ss10 1111	DIVX.L src */

  M32C_ONLY();
  prefix (0, 0, 0);
  div_op (sss, ss, 0, 1, 4);

  /** 0000 0001 1001 ddd w dd00 1110	DSBB.size #IMM,dest */

  DADDI(0,1);

  /** 0000 0001 1sss ddd w dd ss 1010	DSBB.size src,dest */

  DADDV(0,1);

  /** 0000 0001 1001 ddd w dd01 1110	DSUB.size #IMM,dest */

  DADDI(0,0);

  /** 0000 0001 1sss ddd w dd ss 0010	DSUB.size src,dest */

  DADDV(0,0);

  /** 1110 1100				ENTER #IMM */

  imm = IMM(1);
  put_reg (sp, get_reg (sp) - 4);
  mem_put_si (get_reg (sp), get_reg (fb));
  put_reg (fb, get_reg (sp));
  put_reg (sp, get_reg (sp) - imm);

  /** 1111 1100				EXITD */

  put_reg (sp, get_reg (fb));
  put_reg (fb, mem_get_si (get_reg (sp)));
  put_reg (sp, get_reg (sp) + 4);
  put_reg (pc, mem_get_si (get_reg (sp)));
  put_reg (sp, get_reg (sp) + 4);

  /** 1100 ddd w dd01 1110		EXTS.size dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  v = sign_ext (get_src (dc), (w+1)*8);
  dc = widen_sd (dc);
  put_dest (dc, v);
  set_sz (v, (w+1)*2);

  /** 0000 0001 1sss ddd0 dd ss 0111	EXTS.B src,dest */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 1);
  dc = decode_dest23 (ddd, dd, 2);
  v = sign_ext (get_src (sc), 8);
  put_dest (dc, v);
  set_sz (v, 16);

  /** 0000 0001 1sss ddd0 dd ss 1011	EXTZ src,dest */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 1);
  dc = decode_dest23 (ddd, dd, 2);
  v = get_src (sc);
  put_dest (dc, v);
  set_sz (v, 16);

  /** 1101 0011 1110 1dst		FCLR dest */

  set_flags (1 << dst, 0);

  /** 1001 1111				FREIT */

  NOTYET();

  /** 1101 0001 1110 1dst		FSET dest */
  
  set_flags (1 << dst, 1 << dst);

  /** 1010 ddd w dd00 1110		INC.size dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  a = get_src (dc);
  v = a+1;
  tprintf ("%x ++ = %x\n", a, v);
  set_sz (v, w+1);
  put_dest (dc, v);

  /** 1000 sss0 ss0w 0011		INDEXB.size src */
  INDEXOP(1, 1, 1);
  /** 1010 sss0 ss0w 0011		INDEXBD.size src */
  INDEXOP(1, 0, 1);
  /** 1100 sss0 ss0w 0011		INDEXBS.size src */
  INDEXOP(1, 1, 0);
  /** 1001 sss0 ss1w 0011		INDEXL.size src */
  INDEXOP(4, 1, 1);
  /** 1011 sss0 ss1w 0011		INDEXLD.size src */
  INDEXOP(4, 0, 1);
  /** 1001 sss0 ss0w 0011		INDEXLS.size src */
  INDEXOP(4, 1, 0);
  /** 1000 sss0 ss1w 0011		INDEXW.size src */
  INDEXOP(2, 1, 1);
  /** 1010 sss0 ss1w 0011		INDEXWD.size src */
  INDEXOP(2, 0, 1);
  /** 1100 sss0 ss1w 0011		INDEXWS.size src */
  INDEXOP(2, 1, 0);

  /** 1011 1110 vector00			INT #IMM */

  prefix (0, 0, 0);
  trigger_based_interrupt (vector);

  /** 1011 1111				INTO */

  prefix (0, 0, 0);
  if (FLAG_O)
    trigger_fixed_interrupt (0xffffe0);

  /** 1ccc 101c				Jcnd label */

  prefix (0, 0, 0);
  v = sign_ext (IMM(1), 8);
  if (condition_true (ccc*2+c))
    put_reg (pc, orig_pc + 1 + v);

  /** 01dd 101d				JMP.S label */

  prefix (0, 0, 0);
  put_reg (pc, orig_pc + (dd*2+d) + 2);

  /** 1011 1011				JMP.B label */

  prefix (0, 0, 0);
  imm = sign_ext (IMM(1), 8);
  if (imm == -1)
    {
      if (verbose)
	printf("[jmp-to-self detected as exit]\n");
      return M32C_MAKE_HIT_BREAK ();
    }
  put_reg (pc, orig_pc + 1 + imm);

  /** 1100 1110				JMP.W label */

  prefix (0, 0, 0);
  imm = sign_ext (IMM(2), 16);
  put_reg (pc, orig_pc + 1 + imm);

  /** 1100 1100				JMP.A label */
  
  prefix (0, 0, 0);
  imm = IMM(3);
  put_reg (pc, imm);

  /** 1100 sss1 ss00 1111		JMPI.W src */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 2);
  a = get_src (sc);
  a = sign_ext (a, 16);
  put_reg (pc, orig_pc + a);

  /** 1000 sss0 ss00 0001		JMPI.A src */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 3);
  a = get_src (sc);
  put_reg (pc, a);

  /** 1101 1100				JMPS #IMM8 */

  prefix (0, 0, 0);
  imm = IMM(1);
  a = 0xff0000 + mem_get_hi (0xfffe00 - imm * 2);
  put_reg (pc, a);

  /** 1100 1111				JSR.W label */

  prefix (0, 0, 0);
  imm = sign_ext (IMM(2), 16);
  put_reg (sp, get_reg (sp) - 4);
  mem_put_si (get_reg (sp), get_reg (pc));
  put_reg (pc, orig_pc + imm + 1);

  /** 1100 1101				JSR.A label */

  prefix (0, 0, 0);
  imm = IMM(3);
  put_reg (sp, get_reg (sp) - 4);
  mem_put_si (get_reg (sp), get_reg (pc));
  put_reg (pc, imm);

  /** 1100 sss1 ss01 1111		JSRI.W src */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 2);
  a = get_src (sc);
  a = sign_ext (a, 16);
  put_reg (sp, get_reg (sp) - 4);
  mem_put_si (get_reg (sp), get_reg (pc));
  put_reg (pc, orig_pc + a);

  /** 1001 sss0 ss00 0001		JSRI.A src */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 3);
  a = get_src (sc);
  put_reg (sp, get_reg (sp) - 4);
  mem_put_si (get_reg (sp), get_reg (pc));
  put_reg (pc, a);

  /** 1101 1101				JSRS #IMM8 */

  prefix (0, 0, 0);
  imm = IMM(1);
  a = 0xff0000 + mem_get_hi (0xfffe00 - imm * 2);
  put_reg (sp, get_reg (sp) - 4);
  mem_put_si (get_reg (sp), get_reg (pc));
  put_reg (pc, a);

  /** 1101 0101 1010 1dst		LDC #IMM16,dest */

  imm = IMM(2);
  dc = decode_cr_b (dst, CR_B_DCT0);
  put_dest (dc, imm);

  /** 1101 0101 0010 1dst		LDC #IMM24,dest */

  imm = IMM(3);
  dc = decode_cr_b (dst, CR_B_INTB);
  put_dest (dc, imm);

  /** 1101 0101 0110 1dst		LDC #IMM24,dest */

  imm = IMM(3);
  dc = decode_cr_b (dst, CR_B_DMA0);
  put_dest (dc, imm);

  /** 0000 0001 1101 sss1 ss00 1dst	LDC src,dest */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 2);
  dc = decode_cr_b (dst, CR_B_DCT0);
  a = get_src (sc);
  put_dest (dc, a);

  /** 1101 sss1 ss00 0dst		LDC src,dest */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 3);
  dc = decode_cr_b (dst, CR_B_INTB);
  a = get_src (sc);
  put_dest (dc, a);

  /** 0000 0001 1101 sss1 ss00 0dst	LDC src,dest */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 3);
  dc = decode_cr_b (dst, CR_B_DMA0);
  a = get_src (sc);
  put_dest (dc, a);

  /** 1011 0110 1100 0011		LDCTX */

  NOTYET();

  /** 1101 0101 1110 1imm		LDIPL #IMM */

  set_flags (0x7000, imm*0x1000);

  /** 0000 0001 1000 ddd w dd11 1111	MAX.size #IMM,dest */

  prefix (0, 0, 0);
  w++;
  dc = decode_dest23 (ddd, dd, w);
  imm = sign_ext (IMM(w), w*8);
  a = sign_ext (get_src (dc), w*8);
  tprintf ("max %d %d\n", imm, a);
  if (imm > a)
    put_dest (dc, imm);

  /** 0000 0001 1sss ddd w dd ss 1101	MAX.size src,dest */

  prefix (0, 0, 0);
  w++;
  sc = decode_src23 (sss, ss, w);
  dc = decode_dest23 (ddd, dd, w);
  b = sign_ext (get_src (sc), w*8);
  a = sign_ext (get_src (dc), w*8);
  tprintf ("max %d %d\n", b, a);
  if (b > a)
    put_dest (dc, b);

  /** 0000 0001 1000 ddd w dd10 1111	MIN.size #IMM,dest */

  prefix (0, 0, 0);
  w++;
  dc = decode_dest23 (ddd, dd, w);
  imm = sign_ext (IMM(w), w*8);
  a = sign_ext (get_src (dc), w*8);
  tprintf ("min %d %d\n", imm, a);
  if (imm < a)
    put_dest (dc, imm);

  /** 0000 0001 1sss ddd w dd ss 1100	MIN.size src,dest */

  prefix (0, 0, 0);
  w++;
  sc = decode_src23 (sss, ss, w);
  dc = decode_dest23 (ddd, dd, w);
  b = sign_ext (get_src (sc), w*8);
  a = sign_ext (get_src (dc), w*8);
  tprintf ("min %d %d\n", b, a);
  if (b < a)
    put_dest (dc, b);

  /** 1001 ddd w dd10 1111		MOV.size:G #IMM,dest */

  dc = decode_dest23 (ddd, dd, w+1);
  imm = IMM(w+1);
  v = imm;
  tprintf("%x = %x\n", v, v);
  set_sz(v, w+1);
  put_dest (dc, v);

  /** 1011 ddd0 dd11 0001		MOV.L:G #IMM,dest */

  dc = decode_dest23 (ddd, dd, 4);
  imm = IMM(4);
  v = imm;
  tprintf("%x = %x\n", v, v);
  set_sz(v, 4);
  put_dest (dc, v);

  /** 1111 ddd w dd10 immm		MOV.size:Q #IMM4,dest */

  dc = decode_dest23 (ddd, dd, w+1);
  imm = sign_ext (immm, 4);
  v = imm;
  tprintf("%x = %d\n", v, v);
  set_sz(v, w+1);
  put_dest (dc, v);

  /** 00dd 010w				MOV.size:S #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest2 (dd, w+1);
  imm = IMM(w+1);
  put_dest (dc, imm);
  set_sz (imm, w+1);

  /** 10w1 110d				MOV.size:S #IMM,a0/a1 */

  imm = IMM(w ? 3 : 2);
  put_reg (d ? a1 : a0, imm);
  set_sz (imm & addr_mask, w+1);

  /** 00dd 001w				MOV.size:Z #0,dest */

  prefix (0, 1, 0);
  dc = decode_dest2 (dd, w+1);
  put_dest (dc, 0);
  set_sz (0, w+1);

  /** 1sss ddd w dd ss 1011		MOV.size:G src,dest */

  prefix (1, 1, 0);
  sc = decode_src23 (sss, ss, w+1);
  dc = decode_dest23 (ddd, dd, w+1);
  v = get_src (sc);
  put_dest (dc, v);
  set_sz (v, w+1);

  /** 1sss ddd1 dd ss 0011		MOV.L:G src,dest */

  prefix (1, 1, 0);
  sc = decode_src23 (sss, ss, 4);
  dc = decode_dest23 (ddd, dd, 4);
  v = get_src (sc);
  put_dest (dc, v);
  set_sz (v, 4);

  /** VARY SS 01 10 11 */
  /** 00SS 100w				MOV.size:S src,R0L/R0 */

  prefix (0, 1, 0);
  sc = decode_dest2 (SS, w+1);
  v = get_src (sc);
  put_reg (w ? r0 : r0l, v);
  set_sz (v, w+1);

  /** 01ss 111w				MOV.size:S src,R1L/R1 */

  prefix (0, 1, 0);
  sc = decode_dest2 (ss, w+1);
  v = get_src (sc);
  put_reg (w ? r1 : r1l, v);
  set_sz (v, w+1);

  /** VARY DD 01 10 11 */
  /** 00DD 000w				MOV.size:S R0L/R0,dest */

  prefix (0, 1, 0);
  dc = decode_dest2 (DD, w+1);
  v = get_reg (w ? r0 : r0l);
  put_dest (dc, v);
  set_sz (v, w+1);

  /** 01ss 100d				MOV.L:S src,A0/A1 */

  prefix (0, 1, 0);
  sc = decode_dest2 (ss, 4);
  v = get_src (sc);
  put_reg (d ? a1 : a0, v);
  set_sz (v, 4);

  /** 1011 ddd w dd00 1111		MOV.size:G dsp:8[SP], dest */

  prefix (0, 0, 0);
  imm = IMM(1);
  dc = decode_dest23 (ddd, dd, w+1);
  a = get_reg (sp) + sign_ext (imm, 8);
  a &= addr_mask;
  if (w)
    v = mem_get_hi (a);
  else
    v = mem_get_qi (a);
  put_dest (dc, v);
  set_sz (v, w+1);

  /** 1010 sss w ss00 1111		MOV.size:G src,dsp:8[SP] */

  prefix (0, 0, 0);
  sc = decode_dest23 (sss, ss, w+1);
  imm = IMM(1);
  a = get_reg (sp) + sign_ext (imm, 8);
  a &= addr_mask;
  v = get_src (sc);
  if (w)
    mem_put_hi (a, v);
  else
    mem_put_qi (a, v);
  set_sz (v, w+1);

  /** 1101 sss1 ss01 1dst		MOVA src,dest */

  static reg_id map[8] = { r2r0, r3r1, a0, a1 };
  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 1);
  if (!sc.mem || !map[dst])
    UNSUPPORTED();
  put_reg (map[dst], sc.u.addr);

  /** 0000 0001 1011 ddd0 dd hl 1110	MOVdir R0L,dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, 1);
  a = get_src (dc);
  b = get_reg (r0l);
  switch (hl)
    {
    case 0: a = (a & 0xf0) | (b & 0x0f); break;
    case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
    case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
    case 3: a = (a & 0x0f) | (b & 0xf0); break;
    }
  put_dest (dc, a);

  /** 0000 0001 1010 sss0 ss hl 1110	MOVdir src,R0L */

  prefix (0, 0, 0);
  sc = decode_dest23 (sss, ss, 1);
  a = get_reg (r0l);
  b = get_src (dc);
  switch (hl)
    {
    case 0: a = (a & 0xf0) | (b & 0x0f); break;
    case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
    case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
    case 3: a = (a & 0x0f) | (b & 0xf0); break;
    }
  put_reg (r0l, a);

  /** 1011 ddd0 dd01 0001		MOVX #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, 4);
  imm = sign_ext (IMM(1), 8);
  put_dest (dc, imm);
  set_sz (imm, 1);

  /** 1000 ddd w dd01 1111		MUL.size #IMM,dest */

  prefix (0, 1, 0);
  w ++;
  dc = decode_dest23 (ddd, dd, w);
  v = sign_ext (get_src (dc), w*8);
  imm = sign_ext (IMM(w), w*8);
  tprintf("%d * %d = %d\n", v, imm, v*imm);
  v *= imm;
  dc = widen_sd (dc);
  put_dest (dc, v);

  /** 1sss ddd w dd ss 1100		MUL.size src,dest */

  prefix (1, 1, 0);
  w ++;
  sc = decode_src23 (sss, ss, w);
  dc = decode_dest23 (ddd, dd, w);
  a = sign_ext (get_src (sc), w*8);
  b = sign_ext (get_src (dc), w*8);
  tprintf("%d * %d = %d\n", a, b, a*b);
  v = a * b;
  dc = widen_sd (dc);
  put_dest (dc, v);

  /** 0000 0001 1000 sss1 ss01 1111	MUL.L src,R2R0 */

  M32C_ONLY();
  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 4);
  a = sign_ext (get_src (sc), 32);
  b = sign_ext (get_reg (r2r0), 32);
  ll = (long long)a * (long long)b;
  tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll);
  if (ll < b2minsigned[4] || ll > b2maxsigned[4])
    set_flags (FLAGBIT_O, FLAGBIT_O);
  else
    set_flags (FLAGBIT_O, 0);
  put_reg (r2r0, (int)ll);

  /** 1100 sss1 ss11 1110		MULEX src */

  prefix (0, 1, 0);
  sc = decode_dest23 (sss, ss, 2);
  a = sign_ext (get_src (sc), 16);
  b = sign_ext (get_reg (r2r0), 32);
  ll = (long long)a * (long long)b;
  tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll);
  put_reg (r2r0, (int)ll);
  put_reg (r1, (int)(ll >> 32));

  /** 1000 ddd w dd00 1111		MULU.size #IMM,dest */

  prefix (0, 1, 0);
  w ++;
  dc = decode_dest23 (ddd, dd, w);
  v = get_src (dc);
  imm = IMM(w);
  tprintf("%d * %d = %d\n", v, imm, v*imm);
  v *= imm;
  dc = widen_sd (dc);
  put_dest (dc, v);

  /** 1sss ddd w dd ss 0100		MULU.size src,dest */

  prefix (1, 1, 0);
  w ++;
  sc = decode_src23 (sss, ss, w);
  dc = decode_dest23 (ddd, dd, w);
  a = get_src (sc);
  b = get_src (dc);
  tprintf("%d * %d = %d\n", a, b, a*b);
  v = a * b;
  dc = widen_sd (dc);
  put_dest (dc, v);

  /** 0000 0001 1000 sss1 ss00 1111	MULU.L src,R2R0 */

  M32C_ONLY();
  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, 4);
  a = get_src (sc);
  b = get_reg (r2r0);
  ll = (long long)a * (long long)b;
  tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll);
  if (ll < b2minsigned[4] || ll > b2maxsigned[4])
    set_flags (FLAGBIT_O, FLAGBIT_O);
  else
    set_flags (FLAGBIT_O, 0);
  put_reg (r2r0, (int)ll);

  /** 1010 ddd w dd10 1111		NEG.size dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  a = sign_ext (get_src (dc), (w+1)*8);
  v = -a;
  tprintf("%d * -1 = %d\n", a, v);
  set_oszc(v, w+1, v==0);
  put_dest (dc, v);

  /** 1101 1110				NOP */

  tprintf("nop\n");

  /** 1010 ddd w dd01 1110		NOT.size dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  a = get_src (dc);
  v = ~a;
  tprintf("~ %x = %x\n", a, v);
  set_sz(v, w+1);
  put_dest (dc, v);

  /** 1000 ddd w dd10 1111		OR.size:G #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23(ddd, dd, w+1);
  imm = IMM(w+1);
  LOGIC_OP (dc, imm, |);

  /** 01dd 010w				OR.size:S #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest2(dd, w+1);
  imm = IMM (w+1);
  LOGIC_OP (dc, imm, |);

  /** 1sss ddd w dd ss 0101		OR.size:G src,dest */

  prefix (1, 1, 0);
  sc = decode_src23(sss, ss, w+1);
  dc = decode_dest23(ddd, dd, w+1);
  b = get_src (sc);
  LOGIC_OP (dc, b, |);

  /** 1011 ddd w dd10 1111		POP.size dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  if (w)
    a = mem_get_hi (get_reg (sp));
  else
    a = mem_get_qi (get_reg (sp));
  put_reg (sp, get_reg (sp) + 2);
  tprintf("pop%s: %x\n", w ? "hi" : "qi", a);
  put_dest (dc, a);

  /** 1101 0011 1010 1dst		POPC dest */

  prefix (0, 0, 0);
  dc = decode_cr_b (dst, CR_B_DCT0);
  a = mem_get_hi (get_reg (sp));
  put_reg (sp, get_reg (sp) + 2);
  tprintf("pophi: %x\n", a);
  put_dest (dc, a);

  /** 1101 0011 0010 1dst		POPC dest */

  prefix (0, 0, 0);
  dc = decode_cr_b (dst, CR_B_INTB);
  a = mem_get_si (get_reg (sp));
  put_reg (sp, get_reg (sp) + 4);
  tprintf("popsi: %x\n", a);
  put_dest (dc, a);

  /** 1000 1110				POPM dest */

  static int map[] = { r0, r1, r2, r3, a0, a1, sb, fb };
  prefix (0, 0, 0);
  imm = IMM(1);
  tprintf("popm: %x\n", imm);
  for (a=0; a<4; a++)
    if (imm & (1<<a))
      {
	v = mem_get_hi (get_reg (sp));
	put_reg (map[a], v);
	put_reg (sp, get_reg (sp) + 2);
      }
  for (; a<8; a++)
    if (imm & (1<<a))
      {
	v = mem_get_si (get_reg (sp));
	put_reg (map[a], v);
	put_reg (sp, get_reg (sp) + 4);
      }

  /** 1010 111w				PUSH.size #IMM */

  prefix (0, 0, 0);
  imm = IMM(w+1);
  tprintf("push%s: %x\n", w ? "hi" : "qi", imm);
  int a = get_reg (sp) - 2;
  if (w)
    mem_put_hi (a, imm);
  else
    mem_put_qi (a, imm);
  put_reg (sp, a);

  /** 1100 sss w ss00 1110		PUSH.size src */

  prefix (0, 1, 0);
  sc = decode_dest23 (sss, ss, w+1);
  a = get_src (sc);
  put_reg (sp, get_reg (sp) - 2);
  if (w)
    mem_put_hi (get_reg (sp), a);
  else
    mem_put_qi (get_reg (sp), a);
  tprintf("push%s: %x\n", w ? "hi" : "qi", a);

  /** 1011 0110 0101 0011		PUSH.L #IMM32 */

  imm = IMM(4);
  put_reg (sp, get_reg (sp) - 4);
  mem_put_si (get_reg (sp), imm);

  /** 1010 sss0 ss00 0001		PUSH.L src */

  prefix (0, 1, 0);
  sc = decode_dest23 (sss, ss, 4);
  a = get_src (sc);
  put_reg (sp, get_reg (sp) - 4);
  mem_put_si (get_reg (sp), a);

  /** 1011 0sa0 ss00 0001		PUSHA src */

  prefix (0, 0, 0);
  sc = decode_dest23 (sa, ss, 1);
  put_reg (sp, get_reg (sp) - 4);
  mem_put_hi (get_reg (sp), sc.u.addr);
  tprintf("pushsi: %x\n", sc.u.addr);

  /** 1101 0001 1010 1src		PUSHC src */

  prefix (0, 0, 0);
  sc = decode_cr_b (src, CR_B_DCT0);
  a = get_src (sc);
  put_reg (sp, get_reg (sp) - 2);
  mem_put_hi (get_reg (sp), a);
  tprintf("pushhi: %x\n", a);

  /** 1101 0001 0010 1src		PUSHC src */

  prefix (0, 0, 0);
  sc = decode_cr_b (src, CR_B_INTB);
  a = get_src (sc);
  put_reg (sp, get_reg (sp) - 4);
  mem_put_si (get_reg (sp), a);
  tprintf("pushsi: %x\n", a);

  /** 1000 1111				PUSHM src */

  static int map[] = { fb, sb, a1, a0, r3, r2, r1, r0 };
  imm = IMM(1);
  tprintf("pushm: %x\n", imm);
  for (a=0; a<4; a++)
    if (imm & (1<<a))
      {
	put_reg (sp, get_reg (sp) - 4);
	v = get_reg (map[a]);
	mem_put_si (get_reg (sp), v);
      }
  for (; a<8; a++)
    if (imm & (1<<a))
      {
	put_reg (sp, get_reg (sp) - 2);
	v = get_reg (map[a]);
	mem_put_hi (get_reg (sp), v);
      }

  /** 1001 1110				REIT */

  a = get_reg (sp);
  put_reg (pc, mem_get_si (a));
  a += 4;
  put_reg (flags, mem_get_hi (a));
  a += 2;
  put_reg (sp, a);

  /** 1011 1000 010w 0011		RMPA.size */

  int count = get_reg (r3);
  int list1 = get_reg (a0);
  int list2 = get_reg (a1);
  long long sum = get_reg_ll (r3r1r2r0) & 0xffffff;

  while (count)
    {
      if (w)
	{
	  a = sign_ext (mem_get_hi (list1), 16);
	  b = sign_ext (mem_get_hi (list2), 16);
	}
      else
	{
	  a = sign_ext (mem_get_qi (list1), 8);
	  b = sign_ext (mem_get_qi (list2), 8);
	}
      tprintf("%lld + %d * %d = ", sum, a, b);
      sum += a * b;
      tprintf("%lld\n", sum);
      list1 += w ? 2 : 1;
      list2 += w ? 2 : 1;
      count --;
    }
  put_reg (r3, count);
  put_reg (a0, list1);
  put_reg (a1, list2);
  put_reg (r2r0, (int)(sum & 0xffffffffU));
  put_reg (r1, (int)(sum >> 32));

  /** 1011 ddd w dd10 1110		ROLC.size dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  rot_op (dc, 1, 1);

  /** 1010 ddd w dd10 1110		RORC.size dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  rot_op (dc, 1, -1);

  /** 1110 ddd w dd10 immm		ROT.size #IMM, dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  rot_op (dc, IMM4(), -1);

  /** 1010 ddd w dd11 1111		ROT.size R1H,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  a = sign_ext (get_reg (r1h), 8);
  rot_op (dc, a, -1);

  /** 1101 1111				RTS */

  put_reg (pc, mem_get_si (get_reg (sp)));
  put_reg (sp, get_reg (sp) + 4);

  /** 0000 0001 1001 ddd w dd10 1110	SBB.size #IMM, dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  imm = IMM (w+1);
  MATH_OP (dc, imm, !carry, -);

  /** 0000 0001 1sss ddd w dd ss 0110	SBB.size src,dest */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, w+1);
  dc = decode_dest23 (ddd, dd, w+1);
  MATH_OP (dc, get_src (sc), !carry, -);

  /** 1101 ddd1 dd11 cond		SCcond dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, 2);
  if (condition_true (cond))
    put_dest (dc, 1);
  else
    put_dest (dc, 0);

  /** 1011 1000 110w 0011		SCMPU.size */

  ta0 = get_reg (a0);
  ta1 = get_reg (a1);

  for (;;)
    {
      t0 = mem_get_qi (ta0);
      t2 = mem_get_qi (ta1);
      if (w)
	{
	  t1 = mem_get_qi (ta0 + 1);
	  t3 = mem_get_qi (ta1 + 1);
	}
      dif = t0 - t2;
      if (dif == 0 && t0 != 0 && w)
	dif = t1 - t3;
      set_oszc (dif, 1, dif > 0);

      ta0 += w ? 2 : 1;
      ta1 += w ? 2 : 1;

      if (t0 == 0 || t0 != t2)
	break;
      if (w && (t1 == 0 || t1 != t3))
	break;
    }

  /** 1111 ddd w dd00 immm		SHA.size #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  shift_op (dc, 1, IMM4(), 1);

  /** 1010 ddd0 dd10 0001		SHA.L #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, 4);
  imm = sign_ext (IMM(1), 8);
  shift_op (dc, 1, imm, 1);

  /** 1011 ddd w dd11 1110		SHA.size R1H,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  a = sign_ext (get_reg (r1h), 8);
  shift_op (dc, 1, a, 1);

  /** 1100 ddd0 dd01 0001		SHA.L	R1H,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, 4);
  a = sign_ext (get_reg (r1h), 8);
  shift_op (dc, 1, a, 1);

  /** 1100 ddd0 dd10 0001		SHANC.L #IMM,dest */

  M32C_ONLY();
  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, 4);
  imm = sign_ext (IMM(1), 8);
  shift_op (dc, 1, imm, 0);

  /** 1110 ddd w dd00 immm		SHL.size #IMM, dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  shift_op (dc, 0, IMM4(), 1);

  /** 1001 ddd0 dd10 0001		SHL.L #IMM, dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, 4);
  imm = sign_ext (IMM(1), 8);
  shift_op (dc, 0, imm, 1);

  /** 1010 ddd w dd11 1110		SHL.size R1H,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  a = sign_ext (get_reg (r1h), 8);
  shift_op (dc, 0, a, 1);

  /** 1100 ddd0 dd00 0001		SHL.L R1H,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, 4);
  a = sign_ext (get_reg (r1h), 8);
  shift_op (dc, 0, a, 1);

  /** 1000 ddd0 dd10 0001		SHLNC.L #IMM,dest */

  M32C_ONLY();
  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, 4);
  imm = sign_ext (IMM(1), 8);
  shift_op (dc, 0, imm, 0);

  /** 1011 0010 100w 0011		SIN.size */

  v = get_reg (a0);
  a = get_reg (a1);
  b = get_reg (r3);
  if (b) for (;b;)
    {
      if (w)
	mem_put_hi(a, mem_get_hi (v));
      else
	mem_put_qi(a, mem_get_qi (v));
      a += w ? 2 : 1;
      b --;
    }
  put_reg (a0, v);
  put_reg (a1, a);
  put_reg (r3, b);

  /** 1011 0110 100w 0011		SMOVB.size */

  v = get_reg (a0);
  a = get_reg (a1);
  b = get_reg (r3);
  if (b) for (;b;)
    {
      if (w)
	mem_put_hi(a, mem_get_hi (v));
      else
	mem_put_qi(a, mem_get_qi (v));
      v -= w ? 2 : 1;
      a -= w ? 2 : 1;
      b --;
    }
  put_reg (a0, v);
  put_reg (a1, a);
  put_reg (r3, b);

  /** 1011 0000 100w 0011		SMOVF.size */

  v = get_reg (a0);
  a = get_reg (a1);
  b = get_reg (r3);
  if (b) for (;b;)
    {
      if (w)
	mem_put_hi(a, mem_get_hi (v));
      else
	mem_put_qi(a, mem_get_qi (v));
      v += w ? 2 : 1;
      a += w ? 2 : 1;
      b --;
    }
  put_reg (a0, v);
  put_reg (a1, a);
  put_reg (r3, b);

  /** 1011 1000 100w 0011		SMOVU.size */

  v = get_reg (a0);
  a = get_reg (a1);
  do
    {
      if (w)
	mem_put_hi(a, (t0 = mem_get_hi (v)));
      else
	mem_put_qi(a, (t0 = mem_get_qi (v)));
      v += w ? 2 : 1;
      a += w ? 2 : 1;
      if (t0 == 0
	  || (w && ((t0 & 0xff) == 0 || (t0 & 0xff00) == 0)))
	break;
    } while (1);
  put_reg (a0, v);
  put_reg (a1, a);

  /** 1011 0100 100w 0011		SOUT.size */

  v = get_reg (a0);
  a = get_reg (a1);
  b = get_reg (r3);
  for (;b;)
    {
      if (w)
	mem_put_hi(a, mem_get_hi (v));
      else
	mem_put_qi(a, mem_get_qi (v));
      v += w ? 2 : 1;
      b --;
    }
  put_reg (a0, v);
  put_reg (a1, a);
  put_reg (r3, b);

  /** 1011 1000 000w 0011		SSTR.size */

  a = get_reg (a1);
  b = get_reg (r3);
  for (;b;)
    {
      if (w)
	mem_put_hi(a, r0);
      else
	mem_put_qi(a, r0 & 0xff);
      a += w ? 2 : 1;
      b --;
    }
  put_reg (a1, a);
  put_reg (r3, b);

  /** 0000 0001 1101 ddd1 dd01 0src	STC src,dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, 4);
  sc = decode_cr_b (src, CR_B_DMA0);
  a = get_src (sc);
  put_dest (dc, a);

  /** 0000 0001 1101 ddd1 dd01 1src	STC src,dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, 2);
  sc = decode_cr_b (src, CR_B_DCT0);
  a = get_src (sc);
  put_dest (dc, a);

  /** 1101 ddd1 dd01 0src		STC src,dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, 4);
  sc = decode_cr_b (src, CR_B_INTB);
  a = get_src (sc);
  put_dest (dc, a);

  /** 1011 0110 1101 0011		STCX abs16,abs24 */

  NOTYET();

  /** 1001 ddd w dd01 1111		STNZ.size #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  imm = IMM(w+1);
  if (! FLAG_Z)
    put_dest (dc, imm);

  /** 1001 ddd w dd00 1111		STZ.size #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  imm = IMM(w+1);
  if (FLAG_Z)
    put_dest (dc, imm);

  /** 1001 ddd w dd11 1111		STZX.size #IMM1,#IMM2,dest */

  prefix (0, 1, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  a = IMM(w+1);
  b = IMM(w+1);
  if (FLAG_Z)
    put_dest (dc, a);
  else
    put_dest (dc, b);

  /** 1000 ddd w dd11 1110		SUB.size:G #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23(ddd, dd, w+1);
  imm = IMM(w+1);
  MATH_OP (dc, imm, 0, -);

  /** 1001 ddd0 dd11 0001		SUB.L:G #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23(ddd, dd, 4);
  imm = IMM(4);
  MATH_OP (dc, imm, 0, -);

  /** 00dd 111w				SUB.size:S #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest2(dd, w+1);
  imm = IMM (w+1);
  MATH_OP (dc, imm, 0, -);

  /** 1sss ddd w dd ss 1010		SUB.size:G src,dest */

  prefix (1, 1, 0);
  sc = decode_src23(sss, ss, w+1);
  dc = decode_dest23(ddd, dd, w+1);
  b = get_src (sc);
  MATH_OP (dc, b, 0, -);

  /** 1sss ddd1 dd ss 0000		SUB.L:G src,dest */

  prefix (1, 1, 0);
  sc = decode_src23(sss, ss, 4);
  dc = decode_dest23(ddd, dd, 4);
  b = get_src (sc);
  MATH_OP (dc, b, 0, -);

  /** 1001 ddd0 dd01 0001		SUBX #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23(ddd, dd, 4);
  imm = sign_ext (IMM(1), 8);
  MATH_OP (dc, imm, 0, -);

  /** 1sss ddd0 dd ss 0000		SUBX src,dest */

  prefix (1, 1, 0);
  sc = decode_src23(sss, ss, 1);
  dc = decode_dest23(ddd, dd, 4);
  b = sign_ext (get_src (sc), 8);
  MATH_OP (dc, b, 0, -);

  /** 1001 ddd w dd11 1110		TST.size:G #IMM,dest */

  prefix (0, 0, 0);
  dc = decode_dest23 (ddd, dd, w+1);
  imm = IMM(w+1);
  a = get_src (dc);
  v = a & imm;
  set_sz (v, w+1);

  /** 00dd 110w				TST.size:S #IMM,dest */

  prefix (0, 0, 0);
  dc = decode_dest2 (dd, w+1);
  imm = IMM(w+1);
  a = get_src (dc);
  v = a & imm;
  set_sz (v, w+1);

  /** 0000 0001 1sss ddd w dd ss 1001	TST.size:G src,dest */

  prefix (0, 0, 0);
  sc = decode_src23 (sss, ss, w+1);
  dc = decode_dest23 (ddd, dd, w+1);
  b = get_src (sc);
  a = get_src (dc);
  v = a & b;
  set_sz (v, w+1);

  /** 1111 1111				UND */

  trigger_fixed_interrupt (0xffffdc);

  /** 1011 0010 0000 0011		WAIT */

  ;

  /** 1101 ddd w dd00 1src		XCHG.size src,dest */

  dc = decode_dest23 (ddd, dd, w+1);
  sc = decode_src3 (src, w+1);
  a = get_src (dc);
  b = get_src (sc);
  put_dest (dc, b);
  put_dest (sc, a);

  /** 1001 ddd w dd00 1110		XOR.size #IMM,dest */

  prefix (0, 1, 0);
  dc = decode_dest23(ddd, dd, w+1);
  imm = IMM(w+1);
  LOGIC_OP (dc, imm, ^);

  /** 1sss ddd w dd ss 1001		XOR.size src,dest */

  prefix (1, 1, 0);
  sc = decode_src23(sss, ss, w+1);
  dc = decode_dest23(ddd, dd, w+1);
  b = get_src (sc);
  LOGIC_OP (dc, b, ^);

/** */

  return step_result;
}