home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / NDPTYP.ZIP / NDPTYP.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-02-01  |  2.6 KB  |  59 lines

  1. ;Turbo Pascal 4.0 function to check for math coprocessor presence and type
  2. ;using Intel recommended techniques.  Returns 0 if coprocessor not present,
  3. ;87, 287, or 387 if corresponding coprocessor present.
  4.  
  5. ;Reference:  Which Math Coprocessor?, Ted Forgeron, PC Tech Journal, Aug 87.
  6. ;Adapted for use with Turbo Pascal 4.0 by John Haluska, CIS 74000,1106
  7.  
  8. ;function NdpType  :  integer;
  9.  
  10. .287                                     ;accept coprocessor instructions
  11. DATA    SEGMENT  BYTE PUBLIC
  12.         Control  DW   ?                  ;local variable
  13. DATA    ENDS
  14.  
  15. CODE    SEGMENT  BYTE PUBLIC
  16.         ASSUME   CS : CODE, DS : DATA
  17.         PUBLIC   NdpType
  18.  
  19. NdpType         PROC FAR
  20.  
  21. ;test for presence of coprocessor
  22.         MOV      DX,0                    ;load not present message
  23.         FNINIT                           ;initialize math coprocessor
  24.         MOV      BYTE PTR Control+1,0    ;clear memory byte
  25.         FNSTCW   Control                 ;store control word in memory
  26.         MOV      AH,BYTE PTR Control+1   ;upper byte is 03h if
  27.         CMP      AH,03h                  ;  coprocessor is present
  28.         JNE      Msg                     ;no math coprocessor
  29. ;check if 8087
  30.         MOV      DX,87                   ;load 8087 message
  31.         AND      Control, NOT 0080h      ;turn interrupts on (IEM=0)
  32.         FLDCW    Control                 ;load control word
  33.         FDISI                            ;disable interrupts (IEM=1)
  34.         FSTCW    Control                 ;store control word
  35.         TEST     Control, 0080h          ;if IEM=1, then 8087
  36.         JNZ      Msg                     ;display 8087 message
  37. ;check if 80287 or 80387
  38.         MOV      DX,287                  ;load 80287 message
  39.         FINIT                            ;use default infinity mode
  40.         FLD1                             ;generate infinity
  41.         FLDZ                             ;  by dividing 1 by zero
  42.         FDIV                             ;
  43.         FLD      ST                      ;form negative infinity
  44.         FCHS                             ;
  45.         FCOMPP                           ;compare +/- infinity
  46.         FSTSW    Control                 ;equal for 87/287
  47.         FWAIT                            ;wait for FSTSW to complete
  48.         MOV      AX,Control              ;get Ndp control word
  49.         SAHF                             ;store condition bits in flags
  50.         JZ       Msg                     ;its a 80287 if infinities equal
  51.         MOV      DX,387                  ;otherwise, its a 80387
  52. Msg:    MOV      AX,DX                   ;return NdpType in AX
  53.         RET
  54.  
  55. NdpType          ENDP
  56.  
  57. CODE    ENDS
  58.         END
  59.