home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / borland / jnfb88.arc / GETCPU.ARC / GETCPU.ASM < prev    next >
Assembly Source File  |  1987-09-21  |  5KB  |  99 lines

  1.     name GETCPU
  2.     page 55,132
  3.     title    'GETCPU.BIN --- Determines which INTEL CPU is installed'
  4. ;--------------------------------------------------------------------
  5. ; This program determines which Intel CPU is being used in the
  6. ; machine, whether it is an 8088/86, 80188/186, 80286 or 80386.
  7. ; It uses documented and supported differences in flag register bit
  8. ; configurations to determine whether the CPU is an 80286 or 80386,
  9. ; and differences in shifting using CL to determine if it is an
  10. ; 8088/86 or 80188/186. It is intended to be used as an external
  11. ; routine from Turbo Pascal, and returns an integer result in the
  12. ; form of the last three digits of the processor type,
  13. ; as depicted in the table below.
  14. ;
  15. ; If the processor is    The routine returns
  16. ; -------------------    -------------------
  17. ;      80386                    386
  18. ;      80286                    286
  19. ;      80188/186                186
  20. ;      8088/86                   86
  21. ;
  22. ;--------------------------------------------------------------------
  23. ; Declaration of the routine in Pascal V4.0 is:
  24. ;
  25. ;      {$L GETCPU}
  26. ;      function GETCPU : integer; external;
  27. ;
  28. ;--------------------------------------------------------------------
  29. ; To assemble:
  30. ;
  31. ; MASM GETCPU;
  32. ;--------------------------------------------------------------------
  33. ; Code segment begins here
  34. ;--------------------------------------------------------------------
  35. code     segment   para public 'CODE'
  36.     assume    cs:code
  37.     public    getcpu
  38. ;--------------------------------------------------------------------
  39. ; Actual id routine begins here
  40. ;--------------------------------------------------------------------
  41. getcpu   proc near
  42.     pushf              ; Save the flag registers, we use them here...
  43.     xor  ax,ax         ; Clear AX and push it onto the stack
  44.     push ax
  45.     popf           ; Pop 0 into flag registers (all bits to 0),
  46.     pushf          ; attempting to set bits 12-15 of flags to 0's
  47.     pop  ax        ; Recover the saved flags
  48.     and  ax,08000h ; If bits 12-15 of flags are set to zero then
  49.     cmp  ax,08000h ; cpu is 8088/86 or 80188/86
  50.     jz   _8x_18x
  51. ;--------------------------------------------------------------------
  52. ; It is either an 80286 or an 80386, let's find out which...
  53. ;--------------------------------------------------------------------
  54.     mov  ax,07000h ; Try to set flag bits 12-14 to 1's
  55.     push ax        ; Push the test value onto the stack
  56.     popf           ; Pop it into the flag register
  57.     pushf               ; Push it back onto the stack
  58.     pop  ax        ; Pop it into AX for check
  59.     and  ax,07000h ; If bits 12-14 are cleared then the chip is
  60.     jz   _286      ; an 80286
  61. ;--------------------------------------------------------------------
  62. ; Ok, we know it's an 80386 now, tell the user about it!
  63. ;--------------------------------------------------------------------
  64.     mov  ax,386         ; It's not a 286, so it must be a 386
  65.     jmp  DONE
  66. ;--------------------------------------------------------------------
  67. ; Tell the user it is an 80286
  68. ;--------------------------------------------------------------------
  69. _286:    mov  ax,286         ; Get the msg ready
  70.     jmp  DONE
  71. ;--------------------------------------------------------------------
  72. ; We know it is either an 8088/86 or 80188/86, but which one is it?
  73. ;--------------------------------------------------------------------
  74. _8x_18x:
  75.     mov  ax,0ffffh ; Set AX to all 1's
  76.     mov  cl,33          ; Now we try to shift left 33 times. If it's
  77.     shl  ax,cl          ; an 808x it will shift it 33 times, if it's
  78.                    ; an 8018x it will only shift one time.
  79.     jnz  _18x      ; Shifting 33 times would have left all 0's.
  80.                    ; If any 1's are left it's an 80188/186
  81.     mov  ax,86          ; No 1's, it's an 8088/86
  82.     jmp  DONE
  83. ;--------------------------------------------------------------------
  84. ; It's an 80188 or 80186...
  85. ;--------------------------------------------------------------------
  86. _18x:    mov  ax,186   ; Found a 1 in there somewhere, it's an 80188
  87.                        ; or an 80186
  88. ;--------------------------------------------------------------------
  89. ; All done, let's go back...
  90. ;--------------------------------------------------------------------
  91. DONE:    popf          ; Restore the flag registers
  92.     ret
  93. ;--------------------------------------------------------------------
  94. ; End of code and segment
  95. ;--------------------------------------------------------------------
  96. getcpu   endp
  97. code     ends
  98.     end  getcpu
  99.