home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 163_01 / cc52.c < prev    next >
Text File  |  1988-01-31  |  3KB  |  93 lines

  1.  
  2. /*
  3. ** optimize strings beginning "\tJxx $+5\n" for "&&" and "||"
  4. ** ptr addresses 1st byte BEYOND jump
  5. ** jumpinst is "Jxx $+" (null terminated, no 5, \n, or \t)
  6. ** len is length of jump
  7. ** designed to be called from other jump optimizers
  8. */
  9. optim9(ptr, jumpinst) char *ptr, jumpinst[]; {
  10.   char label1[20], label2[20], label3[20], *ptr1, *ptr2;
  11.   int bump, len1, len2, len3, match;
  12.   len1 = len2 = len3 = match = 0;
  13.   if(streq(ptr, "\tJMP CC")) {
  14.     bump = 7;
  15.     ptr1 = ptr + bump;
  16.     ptr2 = label1;
  17.     while((*ptr2++ = *ptr1++) > ' ') ++len1; /* save label #1 */
  18.     *--ptr2 = 0;
  19.     bump += len1 + 1;
  20.     if(streq(ptr+bump, "\tMOV AX,1\n\tJMP CC")) {
  21.       bump += 17;
  22.       ptr1 = ptr + bump;
  23.       ptr2 = label2;
  24.       while((*ptr2++ = *ptr1++) > ' ') ++len2; /* save label #2 */
  25.       *--ptr2 = 0;
  26.       bump += len2 + 1;
  27.       if(streq(ptr+bump, "CC") && streq(ptr+bump+2, label1) &&
  28.           streq(ptr+bump+len1+2, ":\n\tMOV AX,0\nCC") &&
  29.           streq(ptr+bump+len1+16, label2) &&
  30.           streq(ptr+bump+len1+len2+16, ":\n\tAND AX,AX\n\tJNZ $+5\n\tJMP CC")) {
  31.         bump += len1 + len2 + 45;
  32.         ptr1 = ptr + bump;
  33.         ptr2 = label3;
  34.         while((*ptr2++ = *ptr1++) > ' ') ++bump; /* save label #3 */
  35.         *--ptr2 = 0;
  36.         ++bump;
  37.         ot(jumpinst);
  38.         outstr("8");
  39.         nl();
  40.         outstr("CC");
  41.         outstr(label1);
  42.         outstr(":");
  43.         nl();
  44.         ol("MOV AX,0");
  45.         ot("JMP CC");
  46.         outstr(label3);
  47.         nl();
  48.         ol("MOV AX,1 ;optim9 - 1");
  49.         ptr += bump;
  50.         match = 1;
  51.         }
  52.       }
  53.     else if(streq(ptr+bump, "\tMOV AX,0\n\tJMP CC")) {
  54.       bump += 17;
  55.       ptr1 = ptr + bump;
  56.       ptr2 = label2;
  57.       while((*ptr2++ = *ptr1++) > ' ') ++len2; /* save label #2 */
  58.       *--ptr2 = 0;
  59.       bump += len2 + 1;
  60.       if(streq(ptr+bump, "CC") && streq(ptr+bump+2, label1) &&
  61.           streq(ptr+bump+len1+2, ":\n\tMOV AX,1\nCC") &&
  62.           streq(ptr+bump+len1+16, label2) &&
  63.           streq(ptr+bump+len1+len2+16, ":\n\tAND AX,AX\n\tJNZ $+5\n\tJMP CC")) {
  64.         bump += len1 + len2 + 45;
  65.         ptr1 = ptr + bump;
  66.         ptr2 = label3;
  67.         while((*ptr2++ = *ptr1++) > ' ') ++bump; /* save label #3 */
  68.         *--ptr2 = 0;
  69.         ++bump;
  70.         ot(jumpinst);
  71.         outstr("5");
  72.         nl();
  73.         ot("JMP CC");
  74.         outstr(label1);
  75.         nl();
  76.         ol("MOV AX,0");
  77.         ot("JMP CC");
  78.         outstr(label3);
  79.         nl();
  80.         outstr("CC");
  81.         outstr(label1);
  82.         outstr(":");
  83.         nl();
  84.         ol("MOV AX,1 ;optim9 - 2");
  85.         ptr += bump;
  86.         match = 1;
  87.         }
  88.       }
  89.     }
  90.   if (!match) {ot(jumpinst); outstr("5"); nl();}
  91.   return ptr;
  92.   }
  93.