home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c329 / 2.img / EXAMPLES / DISPNDP.C < prev    next >
Encoding:
Text File  |  1989-09-07  |  2.8 KB  |  78 lines

  1. /* The following function displays the numeric and
  2.  * environment registers of the NDP in use. If the
  3.  * program is running on a system with both an 80x87
  4.  * and an mW1167 coprocessor, the function will choose
  5.  * the correct action depending on the compiler options
  6.  * used. In case of an error, the function returns FALSE,
  7.  * otherwise it returns TRUE.
  8.  */
  9.  
  10. int display_ndp()
  11.  
  12. {
  13.         unsigned        i, j, k;
  14.         unsigned        tos_reg; /* Top of Stack Register */
  15.         unsigned        new_tw;  /* Rearranged Tag Word */
  16.         unsigned char   *regptr;
  17.  
  18. #if NDP387==1 || NDP287==1
  19.         printf("\nControl word:\t\t    %04x\n", buff.cw);
  20.         printf("Status word:\t\t    %04x\n", buff.sw);
  21.         printf("Tag word:\t\t    %04x\n", buff.tag);
  22.         printf("IP offset:\t\t%08x\n", buff.ip_off);
  23.         printf("CS selector:\t\t    %04x\n", buff.cs_sel);
  24.         printf("Data operand offset:\t%08x\n", buff.data_off);
  25.         printf("Operand selector:\t    %04x\n\n",
  26.                  buff.oper_sel);
  27.  
  28. /* Which numeric register is Top of Stack ? */
  29.         tos_reg = (buff.sw >> 11) & 7;
  30. /* The following if-else block rearranges the bit pattern
  31.  * of the Tag Word, if necessary, to correctly associate bit
  32.  * pairs representing physical numeric registers 0-7 with
  33.  * relative stack registers ST(0)-ST(7).
  34.  */
  35.         if (tos_reg) {
  36.                 new_tw = buff.tag >> (tos_reg * 2);
  37.                 i = buff.tag << (16 - (tos_reg * 2));
  38.                 new_tw |= i;
  39.         }
  40.         else {
  41.                 new_tw = buff.tag;
  42.         }
  43.  
  44.         printf("Registers:\n");
  45.         regptr = &buff.st0[0];
  46.         for (i = 0; i < 8; i++) {
  47.                 printf("ST%1d = ", i);
  48.                 for (j = 0; j < 10; j++)
  49.                         printf("%02x", *(regptr+9-j));
  50.                 k = (new_tw >> (2*i)) & 3;
  51.                 switch (k) {
  52.                 case 0:         /* Valid number */
  53.                 case 1:         /* Zero */
  54.                         printf("\t%20.14e\n", temp_dbl(regptr));
  55.                         break;
  56.                 case 2: printf ("\tInfinity,NAN,or denormal\n");
  57.                         break;
  58.                 case 3: printf ("\tEmpty register\n");
  59.                         break;
  60.                 }
  61.                 regptr += 10;
  62.         }
  63. #endif
  64.  
  65. #if NDP1167==1
  66.         printf("\nControl word:\t\t    %04x\n", buff.cw);
  67.         printf("Status word:\t\t    %04x\n", buff.sw);
  68.         for (i = 0; i < 16; i++) {
  69.                 printf("%08x %08x %10e\t%10e\t%16e\n",
  70.                         buff.u.regs[2*i], buff.u.regs[2*i+1],
  71.                         buff.u.f_regs[2*i], buff.u.f_regs[2*i+1],
  72.                         buff.u.d_regs[i]);
  73.         }
  74. #endif
  75.         printf ("\n");
  76.         return (TRUE);
  77. }
  78.