home *** CD-ROM | disk | FTP | other *** search
/ Multimedia & CD-ROM 3 / mmcd03-jun1995-cd.iso / utils / various / utils-1 / cputype.asm < prev    next >
Assembly Source File  |  1991-06-24  |  4KB  |  106 lines

  1. ;****************************************************************************
  2. ; CPUTYPE identifies the type of CPU installed in a PC.  On return,
  3. ; ERRORLEVEL is set as follows:
  4. ;
  5. ;       0       8086 or 8088
  6. ;       1       80286
  7. ;       2       80386
  8. ;       3       80486
  9. ;
  10. ; A CPU identified as a 386 could be either a 386DX or 386SX.
  11. ;****************************************************************************
  12.  
  13. code            segment
  14.                 assume  cs:code,ds:code
  15.                 org     100h
  16. begin:          jmp     short main
  17.  
  18. text            db      13,10,"CPU is an 80$"
  19. cpu_8086        db      "86 or 8088$"
  20. cpu_286         db      "286$"
  21. cpu_386         db      "386$"
  22. cpu_486         db      "486$"
  23. crlf            db      13,10,"$"
  24. errorlevel      db      0
  25.  
  26. ;****************************************************************************
  27. ; Procedure MAIN
  28. ;****************************************************************************
  29.  
  30. main            proc    near
  31.                 mov     ah,09h                  ;Print opening message
  32.                 mov     dx,offset text
  33.                 int     21h
  34. ;
  35. ; Test for an 8086/8088 by determing whether SP is decremented before
  36. ; or after a PUSH.
  37. ;
  38.                 mov     dx,offset cpu_8086
  39.                 push    sp
  40.                 pop     ax
  41.                 cmp     sp,ax
  42.                 jne     exit
  43. ;
  44. ; Test for a 286 by attempting to set the Nested Task (NT) bit in the
  45. ; FLAGS register.
  46. ;
  47.                 mov     dx,offset cpu_286
  48.                 inc     errorlevel
  49.                 pushf                           ;Push FLAGS
  50.                 pop     ax                      ;AX = FLAGS
  51.                 or      ax,4000h                ;Set NT bit (bit 14)
  52.                 push    ax                      ;Push new value
  53.                 popf                            ;Pop it into FLAGS
  54.                 pushf                           ;Push FLAGS
  55.                 pop     ax                      ;Pop FLAGS into AX
  56.                 test    ax,4000h                ;Test bit 14 and exit
  57.                 jz      exit                    ;  if it's not set
  58.  
  59.                 and     ax,not 4000h            ;Clear the NT bit before
  60.                 push    ax                      ;  proceeding
  61.                 popf
  62. ;
  63. ; Separate 386s from 486s by attempting to toggle the Alignment Check (AC)
  64. ; bit in the EFLAGS register.
  65. ;
  66.                 .386
  67. not_286:        mov     dx,offset cpu_386
  68.                 inc     errorlevel
  69.                 mov     ebx,esp                 ;Zero lower 2 bits of ESP
  70.                 and     esp,0FFFFFFFCh          ;  to avoid AC fault on 486
  71.                 pushfd                          ;Push EFLAGS register
  72.                 pop     eax                     ;EAX = EFLAGS
  73.                 mov     ecx,eax                 ;ECX = EFLAGS
  74.                 xor     eax,40000h              ;Toggle AC bit (bit 18) in
  75.                                                 ;  EFLAGS register
  76.                 push    eax                     ;Push new value
  77.                 popfd                           ;Put it in EFLAGS
  78.                 pushfd                          ;Push EFLAGS
  79.                 pop     eax                     ;EAX = EFLAGS
  80.                 and     eax,40000h              ;Isolate bit 18 in EAX
  81.                 and     ecx,40000h              ;Isolate bit 18 in ECX
  82.                 cmp     eax,ecx                 ;Are EAX and ECX equal?
  83.                 je      is_386                  ;Yes, then it's a 386
  84.  
  85.                 mov     dx,offset cpu_486       ;No, then it's a 486
  86.                 inc     errorlevel
  87.                 push    ecx                     ;Restore EFLAGS
  88.                 popfd
  89.  
  90. is_386:         mov     esp,ebx                 ;Restore ESP
  91. ;
  92. ; Display CPU type, set return code, and exit.
  93. ;
  94. exit:           mov     ah,09h                  ;Display CPU type
  95.                 int     21h
  96.                 mov     ah,09h
  97.                 mov     dx,offset crlf
  98.                 int     21h
  99.                 mov     ah,4Ch                  ;Exit with ERRORLEVEL set
  100.                 mov     al,errorlevel           ;  indicating CPU type
  101.                 int     21h
  102. main            endp
  103.  
  104. code            ends
  105.                 end     begin
  106.