summaryrefslogtreecommitdiff
path: root/dis88/dishand.c
blob: 833fa2c2ee065f87140e0de1f52993eba36cf2d3 (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
static char *sccsid =
   "@(#) dishand.c, Ver. 2.1 created 00:00:00 87/09/01";

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  *  Copyright (C) 1987 G. M. Harding, all rights reserved  *
  *                                                         *
  * Permission to copy and  redistribute is hereby granted, *
  * provided full source code,  with all copyright notices, *
  * accompanies any redistribution.                         *
  *                                                         *
  * This file contains the source code for most of the spe- *
  * cialized handler routines of the disassembler  program. *
  * (The file disfp.c contains handler routines specific to *
  * the 8087 numeric  co-processor.)  Each handler  routine *
  * interprets the opcode byte  (and subsequent data bytes, *
  * if any)  of a particular family of opcodes,  and is re- *
  * sponsible for generating appropriate output. All of the *
  * code in this file is highly MACHINE-SPECIFIC, and would *
  * have to be rewritten for a different  CPU.  The handler *
  * routines are accessed  only via pointers in the optab[] *
  * array, however, so machine dependencies are confined to *
  * this file, its sister file "disfp.c", and the data file *
  * "distabs.c".                                            *
  *                                                         *
  * All of the code in this file is based on the assumption *
  * of sixteen-bit integers.                                *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "dis.h"              /* Disassembler declarations  */

int segflg;                   /* Segment-override flag      */

unsigned char objbuf[OBJMAX]; /* Buffer for object code     */

int objptr;                   /* Index into objbuf[]        */

unsigned long PC;             /* Current program counter    */

 /* * * * * *  MISCELLANEOUS SUPPORTING ROUTINES  * * * * * */


void
objini(j)                     /* Object code init routine   */

   register int j;

{
   if ((segflg == 1) || (segflg == 2))
      segflg *= 3;
   else
      segflg = 0;
   objptr = 0;
   objbuf[objptr++] = (unsigned char)(j);
}


void
objout()                      /* Object-code output routine */

{
    register int k;

   if ( ! objflg )
      return;
   else
      {
      printf("\t|");
      if (symptr >= 0)
         printf(" %05.5lx:",(PC + 1L - (long)(objptr)));
      for (k = 0; k < objptr; ++k)
         printf(" %02.2x",objbuf[k]);
      putchar('\n');
      }
}


void
badseq(j,k)                   /* Invalid-sequence routine   */

   register int j, k;

{
   printf("\t.byte\t$%02.2x\t\t| invalid code sequence\n",j);
   printf("\t.byte\t$%02.2x\n",k);
}

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This  routine  is the first of several  opcode-specific *
  * handlers,  each of which is  dedicated  to a particular *
  * opcode family.  A pointer to a handler  routine is con- *
  * tained in the second field of each optab[]  entry.  The *
  * dfhand()  routine is the default handler,  invoked when *
  * no other handler is appropriate (generally, when an in- *
  * valid opcode is encountered).                           *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
dfhand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF dfhand()  * * * * * * * * * */

   segflg = 0;

   printf("\t.byte\t$%02.2x",j);

   if (optab[j].min || optab[j].max)
      putchar('\n');
   else
      printf("\t\t| unimplemented opcode\n");

}/* * * * * * * * * * * END OF dfhand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the  single-byte  handler,  invoked  whenever a *
  * one-byte opcode is encountered.                         *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
sbhand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF sbhand()  * * * * * * * * * */

   objini(j);

   if (j == 0x2e)                               /* seg cs   */
      segflg = 1;

   if ((j == 0x26)                              /* seg es   */
    || (j == 0x36)                              /* seg ss   */
    || (j == 0x3e))                             /* seg ds   */
      segflg = 2;

   printf("%s\n",optab[j].text);

   objout();

}/* * * * * * * * * * * END OF sbhand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for most of the processor's regular *
  * arithmetic operations.                                  *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
aohand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF aohand()  * * * * * * * * * */

   register int k;
   int m, n;
   char b[80];

   objini(j);

   switch (j & 7)
      {
      case 0 :
      case 1 :
      case 2 :
      case 3 :
         printf("%s\t",optab[j].text);
         FETCH(k);
         printf("%s\n",mtrans(j,k,TR_STD));
         break;
      case 4 :
         FETCH(k);
	 if( k < 16 )
            printf("%s\tal,*%d\n",optab[j].text,k);
	 else
            printf("%s\tal,*$%02.2x\n",optab[j].text,k);
         break;
      case 5 :
         FETCH(m);
         FETCH(n);
         k = (n << 8) | m;
         if (lookext((long)(k),(PC - 1),b))
            printf("%s\tax,#%s\n",optab[j].text,b);
         else
	    {
	    if( k < 100 || k > 65436 )
	       printf("%s\tax,#%d\n",optab[j].text, (short)k);
	    else
	       printf("%s\tax,#$%04x\n",optab[j].text,k);
	    }
         break;
      default :
         dfhand(j);
         break;
      }

   objout();

}/* * * * * * * * * * * END OF aohand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the  handler for opcodes  which  perform  short *
  * (eight-bit) relative jumps.                             *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
sjhand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF sjhand()  * * * * * * * * * */

   register int k;
   int m;
   unsigned short dest;

   objini(j);

   FETCH(m);

   if (m & 0x80)
      k = 0xff00;
   else
      k = 0;

   k |= m;
   dest = (PC + k + 1);

   printf("%s\t%s\t\t| loc %05.5lx\n",optab[j].text,
    lookup((long) dest,N_TEXT,LOOK_REL,-1L),
    (long) dest);

   objout();

}/* * * * * * * * * * * END OF sjhand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the  handler for a  loosely-knit  family of op- *
  * codes which perform  arithmetic and logical operations, *
  * and which take immediate  data.  The routine's logic is *
  * rather complex,  so,  in an effort to avoid  additional *
  * complexity,  the search for external  references in the *
  * relocation table has been dispensed with. Eager hackers *
  * can try their hand at coding such a search.             *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
imhand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF imhand()  * * * * * * * * * */

   unsigned long pc;
   register int k;
   int offset, oflag, immed, iflag, mod, opi, w, rm;
   int m, n;
   static char a[100], b[30];

   objini(j);

   FETCH(k);

   pc = PC + 1;

   offset = 0;
   mod = (k & 0xc0) >> 6;
   opi = (k & 0x38) >> 3;
   w = j & 1;
   rm = k & 7;

   if ((j & 2)
    && ((opi == 1)
     || (opi == 4)
     || (opi == 6)))
      {
      badseq(j,k);
      return;
      }

   strcpy(a,OPFAM[opi]);

   if ( ! w )
      strcat(a,"b");

   if ((oflag = mod) > 2)
      oflag = 0;

   if ((mod == 0) && (rm == 6))
      {
      FETCH(m);
      FETCH(n);
      offset = (n << 8) | m;
      }
   else if (oflag)
      if (oflag == 2)
         {
         FETCH(m);
         FETCH(n);
         offset = (n << 8) | m;
         }
      else
         {
         FETCH(m);
         if (m & 0x80)
            n = -0xFF;
         else
            n = 0;
         offset = n | m;
         }

   switch (j & 3)
      {
      case 0 :
      case 2 :
         FETCH(immed);
         iflag = 0;
         break;
      case 1 :
         FETCH(m);
         FETCH(n);
         immed = (n << 8) | m;
         iflag = 1;
         break;
      case 3 :
         FETCH(immed);
         if (immed & 0x80)
            immed &= 0xff00;
         iflag = 0;
         break;
      }

   strcat(a,"\t");

   switch (mod)
      {
      case 0 :
         if (rm == 6)
            strcat(a,
             lookup((long)(offset),N_DATA,LOOK_ABS,pc));
         else
            {
            sprintf(b,"(%s)",REGS0[rm]);
            strcat(a,b);
            }
         break;
      case 1 :
      case 2 :
         if (mod == 1)
	 {
            strcat(a,"*");
            sprintf(b,"%d(", (short)offset);
	 }
         else
	 {
            strcat(a,"#");
	    if( offset < 100 || offset > 65436 )
               sprintf(b,"%d(", (short)offset);
	    else
               sprintf(b,"$%04x(",offset);
	 }
         strcat(a,b);
         strcat(a,REGS1[rm]);
         strcat(a,")");
         break;
      case 3 :
         strcat(a,REGS[(w << 3) | rm]);
         break;
      }

   strcat(a,",");
   if (iflag)
   {
      strcat(a,"#");
      if( immed < 100 || immed > 65436 )
         sprintf(b,"%d", (short)immed);
      else
         sprintf(b,"$%04x",immed);
   }
   else
   {
      strcat(a,"*");
      sprintf(b,"%d",immed);
   }
   strcat(a,b);

   printf("%s\n",a);

   objout();

}/* * * * * * * * * * * END OF imhand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the  handler  for  various  "mov"-type  opcodes *
  * which use the mod,  reg,  and r/m  fields of the second *
  * code byte in a standard, straightforward way.           *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
mvhand(j)

   int j;                     /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF mvhand()  * * * * * * * * * */

   register int k, m = j;

   objini(j);

   FETCH(k);

   if ((m == 0x84) || (m == 0x85)      /* Kind of kludgey   */
    || (m == 0xc4) || (m == 0xc5)
    || (m == 0x8d))
      if (m & 0x40)
         m |= 0x03;
      else
         m |= 0x02;

   printf("%s\t%s\n",optab[j].text,mtrans(m,k,TR_STD));

   objout();

}/* * * * * * * * * * * END OF mvhand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for segment-register "mov" opcodes. *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
mshand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF mshand()  * * * * * * * * * */

   register int k;

   objini(j);

   FETCH(k);

   if (k & 0x20)
      {
      badseq(j,k);
      return;
      }

   printf("%s\t%s\n",optab[j].text,mtrans(j,k,TR_SEG));

   objout();

}/* * * * * * * * * * * END OF mshand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the  handler for pops,  other than  single-byte *
  * pops.  (The 8088 allows  popping into any register,  or *
  * directly into memory,  accessed  either  immediately or *
  * through a register and an index.)                       *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
pohand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF pohand()  * * * * * * * * * */

   char *a;
   register int k;

   objini(j);

   FETCH(k);

   if (k & 0x38)
      {
      badseq(j,k);
      return;
      }

   printf("%s\t",optab[j].text);

   a = mtrans((j & 0xfd),k,TR_STD);

   mtrunc(a);

   printf("%s\n",a);

   objout();

}/* * * * * * * * * * * END OF pohand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler routine for intersegment  calls and *
  * jumps.  Its output is never symbolic,  because the host *
  * linker  does not allow  symbolic  intersegment  address *
  * references except by means of symbolic  constants,  and *
  * any such  constants in the symbol  table,  even if they *
  * are of the  appropriate  value,  may be misleading.  In *
  * compiled code,  intersegment  references  should not be *
  * encountered,  and even in assembled  code,  they should *
  * occur infrequently. If and when they do occur, however, *
  * they will be disassembled in absolute form.             *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
cihand(j)

   int j;                     /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF cihand()  * * * * * * * * * */

   register int m, n;

   objini(j);

   printf("%s\t",optab[j].text);

   FETCH(m);
   FETCH(n);

   printf("#$%04.4x,",((n << 8) | m));

   FETCH(m);
   FETCH(n);

   printf("#$%04.4x\n",((n << 8) | m));

   objout();

}/* * * * * * * * * * * END OF cihand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for  "mov"  opcodes with  immediate *
  * data.                                                   *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
mihand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF mihand()  * * * * * * * * * */

   register int k;
   int m, n;
   char b[80];

   objini(j);

   printf("%s",optab[j].text);

   if (j & 8)
      {
      FETCH(m);
      FETCH(n);
      k = ((n << 8) | m);
      if (lookext((long)(k),(PC - 1),b))
         printf("#%s\n",b);
      else
         {
         if( k < 100 || k > 65436 )
            printf("#%d\n",(short)k);
	 else
            printf("#$%04x\n",k);
         }
      }
   else
      {
      FETCH(m);
      printf("*%d\n",m);
      }

   objout();

}/* * * * * * * * * * * END OF mihand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for a family of quick-move opcodes. *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
mqhand(j)

   int j;                     /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF mqhand()  * * * * * * * * * */

   unsigned long pc;
   register int m, n;

   objini(j);

   pc = PC + 1;

   FETCH(m);
   FETCH(n);

   m = (n << 8) | m;

   printf("%s\t",optab[j].text);

   if (j & 2)
      printf("%s,%s\n",
       lookup((long)(m),N_DATA,LOOK_ABS,pc),
       REGS[(j & 1) << 3]);
   else
      printf("%s,%s\n",
       REGS[(j & 1) << 3],
       lookup((long)(m),N_DATA,LOOK_ABS,pc));

   objout();

}/* * * * * * * * * * * END OF mqhand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for a family of quick-test opcodes. *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
tqhand(j)

   int j;                     /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF tqhand()  * * * * * * * * * */

   register int m, n;
   int k;
   char b[80];

   objini(j);

   printf("%s\t%s,",optab[j].text,REGS[(j & 1) << 3]);

   FETCH(m);

   if (j & 1)
      {
      FETCH(n);
      k = ((n << 8) | m);
      if (lookext((long)(k),(PC - 1),b))
         printf("#%s\n",b);
      else
         {
         if( k < 100 || k > 65436 )
            printf("#%d\n",(short)k);
	 else
            printf("#$%04x\n",k);
         }
      }
   else
      {
      if (m & 80)
         m |= -0xFF;
      printf("*%d\n",m);
      }

   objout();

}/* * * * * * * * * * * END OF tqhand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for multiple-byte "return" opcodes. *
  * The 8088 allows returns to take an optional  16-bit ar- *
  * gument,  which  reflects  the  amount to be added to SP *
  * after  the pop of the  return  address.  The idea is to *
  * facilitate  the use of local  parameters  on the stack. *
  * After some  rumination,  it was decided to  disassemble *
  * any such arguments as absolute quantities,  rather than *
  * rummaging  through the symbol table for possible corre- *
  * sponding constants.                                     *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
rehand(j)

   int j;                     /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF rehand()  * * * * * * * * * */

   register int m, n;

   objini(j);

   FETCH(m);
   FETCH(n);

   m = (n << 8) | m;

   printf("%s\t#0x%04.4x\n",optab[j].text,m);

   objout();

}/* * * * * * * * * * * END OF rehand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for "mov"  opcodes involving memory *
  * and immediate data.                                     *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
mmhand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF mmhand()  * * * * * * * * * */

   char *a;
   register int k;
   char b[80];

   objini(j);

   FETCH(k);

   if (k & 0x38)
      {
      badseq(j,k);
      return;
      }

   printf("%s",optab[j].text);

   if ( ! (j & 1) )
      putchar('b');

   a = mtrans((j & 0xfd),(k & 0xc7),TR_STD);

   mtrunc(a);

   printf("\t%s,",a);

   if (j & 1)
      {
      FETCH(j);
      FETCH(k);
      k = (k << 8) | j;
      if (lookext((long)(k),(PC - 1),b))
         printf("#%s\n",b);
      else
         {
         if( k < 100 || k > 65436 )
            printf("#%d\n",(short)k);
	 else
            printf("#$%04x\n",k);
         }
      }
   else
      {
      FETCH(k);
      printf("*%d\n",k);
      }

   objout();

}/* * * * * * * * * * * END OF mmhand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the  handler  for the 8088  family of shift and *
  * rotate instructions.                                    *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
srhand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF srhand()  * * * * * * * * * */

   char *a;
   register int k;

   objini(j);

   FETCH(k);

   if ((k & 0x38) == 0x30)
      {
      badseq(j,k);
      return;
      }

   printf("%s",OPFAM[((k & 0x38) >> 3) + 16]);

   if ( ! (j & 1) )
      putchar('b');

   a = mtrans((j & 0xfd),(k & 0xc7),TR_STD);

   mtrunc(a);

   printf("\t%s",a);

   if (j & 2)
      printf(",cl\n");
   else
      printf(",*1\n");

   objout();

}/* * * * * * * * * * * END OF srhand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for the ASCII-adjust opcodes.       *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
aahand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF aahand()  * * * * * * * * * */

   register int k;

   objini(j);

   FETCH(k);

   if (k != 0x0a)
      {
      badseq(j,k);
      return;
      }

   printf("%s\n",optab[j].text);

   objout();

}/* * * * * * * * * * * END OF aahand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for port I/O opcodes  which specify *
  * the port address as an immediate operand.               *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
iohand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF iohand()  * * * * * * * * * */

   register int k;

   objini(j);

   FETCH(k);

   printf("%s\t$%02.2x\n",optab[j].text,k);

   objout();

}/* * * * * * * * * * * END OF iohand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the  handler  for opcodes  which  perform  long *
  * (sixteen-bit) relative jumps and calls.                 *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
ljhand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF ljhand()  * * * * * * * * * */

   register int k;
   int m, n;
   unsigned short dest;

   objini(j);

   FETCH(m);
   FETCH(n);

   k = (n << 8) | m;
   dest = PC + k + 1;

   printf("%s\t%s\t\t| loc %05.5lx\n",optab[j].text,
          lookup((long)dest,N_TEXT,LOOK_LNG,(PC - 1L)),
          (long)dest);

   objout();

}/* * * * * * * * * * * END OF ljhand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for a pair of oddball opcodes (0xf6 *
  * and 0xf7) which perform miscellaneous arithmetic opera- *
  * tions not dealt with elsewhere.                         *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
mahand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF mahand()  * * * * * * * * * */

   char *a;
   register int k;
   char b[80];

   objini(j);

   FETCH(k);

   a = mtrans((j & 0xfd),(k & 0xc7),TR_STD);

   mtrunc(a);

   switch (((k = objbuf[1]) & 0x38) >> 3)
      {
      case 0 :
         printf("\ttest");
         break;
      case 1 :
         badseq(j,k);
         return;
      case 2 :
         printf("\tnot");
         break;
      case 3 :
         printf("\tneg");
         break;
      case 4 :
         printf("\tmul");
         break;
      case 5 :
         printf("\timul");
         break;
      case 6 :
         printf("\tdiv");
         break;
      case 7 :
         printf("\tidiv");
         break;
      }

   if ( ! (j & 1) )
      putchar('b');

   printf("\t%s",a);

   if (k & 0x38)
      putchar('\n');
   else
      if (j & 1)
         {
         FETCH(j);
         FETCH(k);
         k = (k << 8) | j;
         if (lookext((long)(k),(PC - 1),b))
            printf(",#%s\n",b);
         else
            printf(",#$%04x\n",k);
         }
      else
         {
         FETCH(k);
         printf(",*%d\n",k);
         }

   objout();

}/* * * * * * * * * * * END OF mahand() * * * * * * * * * * */

 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                         *
  * This is the handler for miscellaneous jump, call, push, *
  * and increment/decrement opcodes  (0xfe and 0xff)  which *
  * are not dealt with elsewhere.                           *
  *                                                         *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void
mjhand(j)

   register int j;            /* Pointer to optab[] entry   */

{/* * * * * * * * * *  START OF mjhand()  * * * * * * * * * */

   char *a;
   register int k;

   objini(j);

   FETCH(k);

   a = mtrans((j & 0xfd),(k & 0xc7),TR_STD);

   mtrunc(a);

   switch (((k = objbuf[1]) & 0x38) >> 3)
      {
      case 0 :
         printf("\tinc");
         if ( ! (j & 1) )
            putchar('b');
         putchar('\t');
         break;
      case 1 :
         printf("\tdec");
         if ( ! (j & 1) )
            putchar('b');
         putchar('\t');
         break;
      case 2 :
         if (j & 1)
            printf("\tcall\t@");
         else
            goto BAD;
         break;
      case 3 :
         if (j & 1)
            printf("\tcalli\t@");
         else
            goto BAD;
         break;
      case 4 :
         if (j & 1)
            printf("\tjmp\t@");
         else
            goto BAD;
         break;
      case 5 :
         if (j & 1)
            printf("\tjmpi\t@");
         else
            goto BAD;
         break;
      case 6 :
         if (j & 1)
            printf("\tpush\t");
         else
            goto BAD;
         break;
      case 7 :
 BAD :
         badseq(j,k);
         return;
      }

   printf("%s\n",a);

   objout();

}/* * * * * * * * * * * END OF mjhand() * * * * * * * * * * */