home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol10n20.zip / CPUTYPE.ASM < prev    next >
Assembly Source File  |  1991-10-28  |  3KB  |  76 lines

  1. ; CPUTYPE.ASM - Returns Intel CPU type.  Adapted from
  2. ;               source code distributed to ISVs by Intel Corp.
  3. ;
  4. ; Call with:    N/A
  5. ;
  6. ; Returns:      AX = CPU type 
  7. ;                    0086H = 8086 or 8088
  8. ;                    0286H = 80286
  9. ;                    0386H = 80386SX or 80386DX
  10. ;                    0486H = 80486SX or 80486DX
  11. ;
  12. ; Destroys:     upper 16-bits of EAX and ECX on 386/486
  13.  
  14. _TEXT   segment word use16 public 'CODE'
  15.  
  16.         assume  cs:_TEXT
  17.  
  18.         public  cputype
  19. cputype proc    near
  20.  
  21.         pushf                           ; save copy of flags and
  22.         push    bx                      ; other affected registers
  23.         push    cx
  24.         pushf                           ; now try to clear bits 12-15
  25.         pop     ax                      ; of CPU flags
  26.         and     ax,0fffh
  27.         push    ax                      ; set modified CPU flags
  28.         popf
  29.         pushf
  30.         pop     ax                      ; get flags again
  31.         and     ax,0f000h               ; if bits 12-15 are still       
  32.         cmp     ax,0f000h               ; set, this is 8086/88
  33.         jne     cpu1                    ; jump, not 8086/88
  34.         mov     ax,0086h                ; set AX = 86/88 CPU type
  35.         jmp     cpux                    ; and exit
  36.  
  37. cpu1:   or      ax,0f000h               ; must be 286 or later, 
  38.         push    ax                      ; now try to set bits 12-15
  39.         popf                            ; of CPU flags
  40.         pushf
  41.         pop     ax                      ; if bits 12-15 can't be
  42.         and     ax,0f000h               ; set, this is a 286
  43.         jnz     cpu2                    ; jump, not 80286
  44.         mov     ax,286h                 ; set AX = 286 CPU type
  45.         jmp     cpux                    ; and exit
  46.  
  47. cpu2:   mov     bx,sp                   ; 386 or later, save SP
  48.         and     sp,not 3                ; avoid stack alignment fault
  49.         pushfd                          ; get value of EFLAGS
  50.         pop     eax
  51.         mov     ecx,eax                 ; save copy of EFLAGS 
  52.         xor     eax,40000h              ; flip AC bit in EFLAGS
  53.         push    eax                     ; try and force EFLAGS
  54.         popfd
  55.         pushfd                          ; get back EFLAGS value
  56.         pop     eax
  57.         mov     sp,bx                   ; restore old stack pointer
  58.         xor     eax,ecx                 ; can AC bit be changed?
  59.         jnz     cpu3                    ; no, jump, not a 386
  60.         mov     ax,0386h                ; set AX = 386 CPU type
  61.         jmp     cpux                    ; and exit
  62.  
  63. cpu3:   mov     ax,0486h                ; set AX = 486 CPU type 
  64.  
  65. cpux:   pop     cx                      ; restore registers
  66.         pop     bx
  67.         popf                            ; restore original flags
  68.         ret                             ; return with AX = cpu type
  69.  
  70. cputype endp
  71.  
  72. _TEXT   ends
  73.  
  74.         end     
  75.  
  76.