home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Source / GNU / cctools / as / m98k-check.c < prev    next >
C/C++ Source or Header  |  1993-02-05  |  2KB  |  115 lines

  1. #include "m98k-opcode.h"
  2. char *cond[] = { "lt", "gt", "eq", "un"};
  3. char *pred[] = { "+", "-" };
  4. main()
  5. {
  6.     long i, j, x, d, p;
  7.  
  8.     for(i = 0; *(m98k_opcodes[i].name) != '\0'; i++){
  9.         printf("\t%s", m98k_opcodes[i].name);
  10.         if(IS_BRANCH_CONDITIONAL(m98k_opcodes[i].opcode)){
  11.         p = bits(5) & 1;
  12.         printf("%s", pred[p]);
  13.         }
  14.         if(m98k_opcodes[i].ops[0].type == NONE)
  15.         printf("\n");
  16.         else
  17.         printf("\t");
  18.         d = 0;
  19.         for(j = 0; j < 5 && m98k_opcodes[i].ops[j].type != NONE; j++){
  20.         switch(m98k_opcodes[i].ops[j].type){
  21.         case PCREL:
  22.             printf("_relitive");
  23.             break;
  24.         case BADDR:
  25.             printf("_absolute");
  26.             break;
  27.         case D:
  28.             printf("0x%04x(", bits(16));
  29.             d = 1;
  30.             break;
  31.         case DS:
  32.             printf("0x%04x(", bits(14) << 2);
  33.             d = 1;
  34.             break;
  35.         case SI:
  36.         case UI:
  37.             printf("0x%04x", bits(16));
  38.             break;
  39.         case GREG:
  40.             printf("r%d", bits(5) );
  41.             break;
  42.         case G0REG:
  43.             printf("r%d", bits(5) | 0x1 );
  44.             break;
  45.         case FREG:
  46.             printf("f%d", bits(5) );
  47.             break;
  48.         case SGREG:
  49.             printf("sr%d", bits(4) );
  50.             break;
  51.         case SPREG:
  52.             printf("%d", bits(10) );
  53.             break;
  54.         case BCND:
  55.             printf("cr%d+%s", bits(3), cond[bits(2)] );
  56.             break;
  57.         case CRF:
  58.         case CRFONLY:
  59.             x = bits(3);
  60.             printf("cr%d", x == 0 ? 1 : x);
  61.             break;
  62.         case sh:
  63.             printf("%d", bits(6) );
  64.             break;
  65.         case mb:
  66.             printf("%d", bits(6) );
  67.             break;
  68.         case NUM0:
  69.         case NUM:
  70.             if(j == 0 &&
  71.                IS_BRANCH_CONDITIONAL(m98k_opcodes[i].opcode)){
  72.             x = bits(m98k_opcodes[i].ops[j].width);
  73.             if(m98k_opcodes[i].ops[2].type == PCREL)
  74.                 if(p == 0) /* + with negative disp */
  75.                 x &= 0xfffffffe; 
  76.                 else
  77.                 x |= 1; 
  78.             else
  79.                 if(p == 0) /* + with positive disp */
  80.                 x |= 1; 
  81.                 else
  82.                 x &= 0xfffffffe; 
  83.             if(x == 20)
  84.                 x = 0;
  85.             printf("%d", x);
  86.             }
  87.             else
  88.             printf("%d", bits(m98k_opcodes[i].ops[j].width) );
  89.             break;
  90.         }
  91.         if(j == 5 || m98k_opcodes[i].ops[j+1].type == NONE){
  92.             if(d == 1)
  93.             printf(")\n");
  94.             else
  95.             printf("\n");
  96.         }
  97.         else{
  98.             if(m98k_opcodes[i].ops[j].type != D &&
  99.                m98k_opcodes[i].ops[j].type != DS)
  100.             printf(",");
  101.         }
  102.         }
  103.     }
  104.     exit(0);
  105. }
  106.  
  107. bits(
  108. unsigned long width)
  109. {
  110.      static int x = 1;
  111.  
  112.     x = (x + 1) & ((1 << width) - 1);
  113.     return(x);
  114. }
  115.