home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / borland / jnfb88.arc / COMINC.ARC / GETCPUTB.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-10-15  |  5.7 KB  |  124 lines

  1.     name GETCPU
  2.     page 55,132
  3.     title     'GETCPU.BIN --- Determines which INTEL CPU is installed'
  4. ;--------------------------------------------------------------------
  5. ; By Juan Jiminez -- Modified for Turbo Basic by Bruce Tonkin
  6. ;   Last modified 10/15/87
  7. ;
  8. ; This program determines which one of the Intel CPU's is being used
  9. ; in the machine, whether it is an 8088/86, 80188/186, 80286 or 80386.
  10. ; It uses the differences in flag register bit configurations to
  11. ; determine whether the CPU is an 80286 or 80386, and the differences
  12. ; in shifting using CL to determine if it is an 8088/86 or
  13. ; 80188/186.  It returns an integer result in the form of the last
  14. ; three digits of the processor type, as depicted in the table below.
  15. ;
  16. ; If the processor is    The routine returns
  17. ; -------------------    -------------------
  18. ;      80386                    386
  19. ;      80286                    286
  20. ;      80188/186                186
  21. ;      8088/86                   86
  22. ;
  23. ;--------------------------------------------------------------------
  24. ; Use of the routine in Turbo BASIC is:
  25. ;   CALL GETCPU(X%)
  26. ;
  27. ; Where GETCPU is an inline subprogram of form:
  28. ;
  29. ;   SUB GETCPU INLINE
  30. ;   $INLINE "GETCPU.BIN"
  31. ;   END SUB
  32. ;
  33. ; Alternatively, GETCPU may be placed inline by means of byte values
  34. ; generated with Bruce Tonkin's COM2INC utility.  See text for this
  35. ; listing.
  36. ;
  37. ;--------------------------------------------------------------------
  38. ; To assemble:
  39. ;
  40. ; MASM GETCPU,,,;
  41. ; LINK GETCPU,,,;
  42. ; EXE2BIN GETCPU.EXE GETCPU.COM
  43. ;
  44. ;--------------------------------------------------------------------
  45. ; Code segment begins here
  46. ;--------------------------------------------------------------------
  47. cseg     segment   para public 'CODE'
  48.     assume    cs:cseg,ds:cseg,es:cseg,ss:cseg
  49.     org  100h
  50. ;--------------------------------------------------------------------
  51. ; Actual id routine begins here
  52. ;--------------------------------------------------------------------
  53. getcpu   proc near
  54.     push bp        ; Turbo Basic requires you save the base pointer.
  55.     mov bp,sp      ; Move the stack pointer to bp.
  56.     les di,[bp+6]  ; Offset address of the integer parameter.
  57. ; These first three instructions have changed from Juan's original
  58. ; code.  See the Turbo BASIC manual, page 401, for a small example
  59. ; program and explanations of the logic.  Fortunately, the original
  60. ; routine didn't use di or the direction flag.
  61. ; Turbo BASIC doesn't demand that you save and restore the flags,
  62. ; but I will leave that part of the program logic alone--the changes
  63. ; I've made will be easier to see that way.
  64.     pushf          ; Save the flag registers, we use them here...
  65.     xor  ax,ax     ; Clear AX and push it onto the stack
  66.     push ax
  67.     popf           ; Pop 0 into flag registers (all bits to 0),
  68.     pushf          ; attempting to set bits 12-15 of flags to 0's
  69.     pop  ax        ; Recover the saved flags
  70.     and  ax,08000h ; If bits 12-15 of flags are set to zero then
  71.     cmp  ax,08000h ; cpu is 8088/86 or 80188/86
  72.     jz   _8x_18x
  73. ;--------------------------------------------------------------------
  74. ; It is either an 80286 or an 80386, let's find out which...
  75. ;--------------------------------------------------------------------
  76.     mov  ax,07000h ; Try to set flag bits 12-14 to 1's
  77.     push ax        ; Push the test value onto the stack
  78.     popf           ; Pop it into the flag register
  79.     pushf          ; Push it back onto the stack
  80.     pop  ax        ; Pop it into AX for check
  81.     and  ax,07000h ; If bits 12-14 are cleared then the chip is
  82.     jz   _286      ; an 80286
  83. ;--------------------------------------------------------------------
  84. ; Ok, we know it's an 80386 now, tell the user about it!
  85. ;--------------------------------------------------------------------
  86.     mov  ax,386         ; It's not a 286, so it must be a 386
  87.     jmp  DONE
  88. ;--------------------------------------------------------------------
  89. ; Tell the user it is an 80286
  90. ;--------------------------------------------------------------------
  91. _286:    mov  ax,286         ; Get the msg ready
  92.     jmp  DONE
  93. ;--------------------------------------------------------------------
  94. ; We know it is either an 8088/86 or 80188/86, but which one is it?
  95. ;--------------------------------------------------------------------
  96. _8x_18x:
  97.     mov  ax,0ffffh ; Set AX to all 1's
  98.     mov  cl,33          ; Now we try to shift left 33 times. If it's
  99.     shl  ax,cl          ; an 808x it will shift it 33 times, if it's
  100.                    ; an 8018x it will only shift one time.
  101.     jnz  _18x      ; Shifting 33 times would have left all 0's.
  102.                    ; If any 1's are left it's an 80188/186
  103.     mov  ax,86          ; No 1's, it's an 8088/86
  104.     jmp  DONE
  105. ;--------------------------------------------------------------------
  106. ; It's an 80188 or 80186...
  107. ;--------------------------------------------------------------------
  108. _18x:    mov  ax,186    ; Found a 1 in there somewhere, it's an 80188
  109.                         ; or an 80186
  110. ;--------------------------------------------------------------------
  111. ; All done, let's go back...
  112. ;--------------------------------------------------------------------
  113. DONE:    popf           ; Restore the flag registers
  114.     cld                 ; clear direction flag
  115.     stosw               ; store ax in location for numeric variable
  116.     pop bp              ; restore base pointer
  117. ;   ret                  for Turbo BASIC, the ret must *not* be used.
  118. ;--------------------------------------------------------------------
  119. ; End of code and segment
  120. ;--------------------------------------------------------------------
  121. getcpu   endp
  122. cseg     ends
  123.     end  getcpu
  124.