home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / WHCHCPU.ZIP / WHICHCPU.ASM < prev    next >
Assembly Source File  |  1993-09-24  |  6KB  |  153 lines

  1. ;
  2. ; WHICHCPU.ASM - Copyright (C) 1993 - Tony Doimeadios - All Rights Reserved
  3. ;
  4. ;         Made-----------: 09/24/93
  5. ;         Last Modified--: 09/24/93
  6. ;
  7. ;         This function will return the type of cpu in the system
  8. ;           88
  9. ;           286
  10. ;           386
  11. ;           486
  12. ;
  13. ;         How to use it:
  14. ;           This function is linked in with QB4.5 or PDS7.1
  15. ;           Declare Function WhichCPU%()
  16. ;           Print WhichCPU%
  17. ;           would declare and activate the function.
  18. ;
  19. ;         Technical Details:
  20. ;           I used Turbo Assembler 3.0 to compile this source code.
  21. ;           TASM WHICHCPU
  22. ;           LIB WHICHCPU.LIB +WHICHCPU.OBJ;
  23. ;           LINK /Q /SEG:1024 WHICHCPU.LIB,,NUL,QBXQLB;
  24. ;           This produces WHICHCPU.LIB and WHICHCPU.QLB
  25. ;           To load it into QB/QBX: QBX /L WHICHCPU
  26. ;
  27. ;
  28. ;
  29. ;
  30. ;         This program is hereby released into the Public Domain.
  31. ;           This program can be freely copied and distributed as
  32. ;           long as the information in this block of comments is
  33. ;           not changed.
  34. ;
  35. ;         If you have any problems, complaints or requests, you can
  36. ;           address them to the author.  I'm always happy to hear
  37. ;           from people that use my programs.
  38. ;            ┌─────────────────────────────────────────────────────┐ 
  39. ;            │ Tony Doimeadios, P.O. Box 431, Brunswick, GA  31521 │
  40. ;            └─────────────────────────────────────────────────────┘
  41.     
  42.     
  43.     DOSSEG
  44.     .MODEL MEDIUM, BASIC
  45.     .DATA
  46.  
  47.     
  48.     .CODE
  49.     mov ax,@Data
  50.     mov ds,ax                   ;set DS to point to the data segment
  51.  
  52.     public WhichCPU
  53.  
  54.  
  55. ;---------------------------------------------------------------------
  56. WhichCPU PROC FAR
  57.     
  58.     ;this is a BASIC FUNCTION that returns a number, indicating cpu type
  59.     ;usage--: PRINT WhichCPU%
  60.     
  61.     ;Determine whether the CPU in use is an 8086/88, an 80286,
  62.     ;an 80386 or an 80486.  Returns the CPU type in the AX register.
  63.  
  64.     ;The first step is to determine whether the chip is an 8086/8088.
  65.     ;The key difference is based on what the CPU does when it executes
  66.     ;the PUSH instruction.  The 8086/8088 decrements the stack pointer
  67.     ;first, then writes the saved value to the stack, then decrement
  68.     ;the stack pointer.  Thus, when SP is pushed, and the pushed value
  69.     ;is popped off, the value popped off will equal the current stack 
  70.     ;pointer, unless the chip is an 8086 or an 8088.
  71.     
  72.     push sp                     ;push sp
  73.     pop ax                      ;retrieve value
  74.     cmp ax,sp                   ;is it the same value that was pushed?
  75.     je Try286                   ;if same, it is a 80286 or higher
  76.     mov ax,88                   ;nope, set register to reflect 8088
  77.     jmp short Done              ;bail out
  78.  
  79.  
  80.  
  81.     ;the second step is to determine whether the chip is an 80286.
  82.     ;The key difference is the IOPL bits in the flag register; the 80386
  83.     ;and 80486 has them, the 80286 does not.  The 80286 will not allow them
  84.     ;to be set; the 80386 and 80486 will.
  85.  
  86. Try286:
  87.     pushf                       ;push flags
  88.     pop ax                      ;retreive them
  89.     or ax,03000h                ;set IOPL bits
  90.     push ax                     ;stuff back
  91.     popf                        ;pop flags back - this is where the 80286 
  92.                                 ; will put them back the way they were
  93.     pushf                       ;push them back
  94.     pop ax                      ;see if CPU overrode the IOPL bits
  95.     test ax,03000h              ;if the IOPL bits are reset, the CPU did
  96.                                 ; and the chip is an 80286
  97.     jnz Try386                  ;nope, go see if we're an 80386
  98.     mov ax,286                  ;set register to reflect we're an 80286
  99.     jmp short Done              ;bail out
  100.  
  101.  
  102.     
  103.     
  104.     
  105.     ;the third step is to determine whether the chip is an 80386.
  106.     ;the key difference is the alignment check bit in the flags
  107.     ;register: the 80486 has one, the 80386 does not.  As with the
  108.     ;80286 and the IOPL bits, the 80386 will not let you set that bit,
  109.     ;but the 80486 will.
  110.  
  111. Try386:
  112.     db 66h                      ;(32 bit)
  113.     pushf                       ;push extended flags register
  114.     pop ax                      ;read low word
  115.     and ax,00fffh               ;clear IOPL bits - level zero
  116.     pop dx                      ;read high word
  117.     or dx,00004h                ;set alignment check bit
  118.     push dx                     ;push flags back
  119.     push ax                     ;push flags back
  120.     db 66h                      ;(32 bit)
  121.     popf                        ;pop flags register - this is where
  122.                                 ; the 80386 will undo your work
  123.     db 66h                      ;(32 bits) 
  124.     pushf                       ;push flags back
  125.     pop ax                      ;read what we did
  126.     pop dx                      ;find out if the CPU reset the
  127.                                 ; alignment check bit
  128.     test dx,4                   ;
  129.     jnz short Try486            ;if it didn't, the chip is an 80486
  130.     mov ax,386                  ;set register to reflect we're an 8386
  131.     jmp short Done              ;bail out
  132.  
  133.  
  134.     
  135.     
  136.  
  137.     ;this routine does NOT take into account the Pentium (80586)
  138.     ;therefore, this routine will report an '486' for both the
  139.     ;80486 and the Pentium chips
  140.     
  141. Try486:
  142.     mov ax,486                  ;must be a 80486
  143.  
  144.  
  145. Done:    
  146.     ret                         ;we're thru - bail out
  147.  
  148. WhichCPU ENDP
  149. ;---------------------------------------------------------------------
  150.  
  151.  
  152.     END
  153.