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

  1.     name    C_GETCPU
  2.     page    55,132
  3.     title    "C_GETCPU -- 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 C, and returns an integer result in the form
  12. ; the last three digits of the processor type, as depicted in the
  13. ; table below.  This code is designed for the TINY/SMALL modem.
  14. ; See page 254 of the Turbo C User's Guide for information on how
  15. ; to modify this routine for other memory models.
  16. ;
  17. ; If the processor is     The routine returns
  18. ; -------------------     -------------------
  19. ;      80386                     386
  20. ;      80286                     286
  21. ;      80188/186                 186
  22. ;      8088/86                    86
  23. ;
  24. ;--------------------------------------------------------------------
  25. ; Declaration of the routine in Turbo C is:
  26. ;
  27. ; int C_GETCPU();
  28. ;
  29. ;--------------------------------------------------------------------
  30. ; To assemble:
  31. ;
  32. ; MASM C_GETCPU,,,;
  33. ;
  34. ;--------------------------------------------------------------------
  35. ; Code segment begins here
  36. ;--------------------------------------------------------------------
  37.             ; Required by Turbo C for small memory model
  38. _TEXT    segment byte public 'CODE'
  39.     assume cs:_TEXT        ; Ditto
  40. ;--------------------------------------------------------------------
  41. ; Actual ID routine begins here
  42. ;--------------------------------------------------------------------
  43.     public    _C_GETCPU    ; Make sure Turbo C can get here
  44. _C_GETCPU proc    near        ; Entry point for the subroutine
  45.     pushf        ; Save flag registers, we use them here
  46.     xor    ax,ax    ; Clear AX and...
  47.     push    ax    ; ...push it onto the stack
  48.     popf        ; Pop 0 into flag registers (all bits to 0),
  49.     pushf        ; attempting to set bits 12-15 of flags to 0's
  50.     pop    ax        ; Recover the save flags
  51.     and    ax,08000h    ; If bits 12-15 of flags are set to
  52.     cmp    ax,08000h    ; zero then it's 8088/86 or 80188/186
  53.     jz    _8x_18x
  54. ;--------------------------------------------------------------------
  55. ; It is either an 80286 or an 80386, let's find out which...
  56. ;--------------------------------------------------------------------
  57.     mov    ax,07000h    ; Try to set flag bits 12-14 to 1's
  58.     push    ax        ; Push the test value onto the stack
  59.     popf            ; Pop it into the flag register
  60.     pushf            ; Push it back onto the stack
  61.     pop    ax        ; Pop it into AX for check
  62.     and    ax,07000h    ; if bits 12-14 are cleared then
  63.     jz    _286        ; the chip is an 80286
  64. ;--------------------------------------------------------------------
  65. ; Ok, we know it's an 80386 now, tell the user about it!
  66. ;--------------------------------------------------------------------
  67.     mov    ax,386    ; It's not a 286, so it must be an 80386
  68.     jmp    DONE    ; (at least until the 80486 comes out...)
  69. ;--------------------------------------------------------------------
  70. ; Tell the user it's an 80286
  71. ;--------------------------------------------------------------------
  72. _286:    mov    ax,286        ; Get the msg ready
  73.     jmp    DONE        ; Bye
  74. ;--------------------------------------------------------------------
  75. ; We know it is either an 8088/86 or 80188/86, but which one is it?
  76. ;--------------------------------------------------------------------
  77. _8x_18x:
  78.     mov    ax,0FFFFh    ; Set AX to all 1's
  79.     mov    cl,33    ; Now we try to shift left 33 time. If it's
  80.     shl    ax,cl    ; an 808x it will shift it 33 times, if it's
  81.             ; an 8018x it wil only shift one time
  82.     jnz    _18x    ; Shifting 33 times would have left all 0's
  83.             ; if any 1's are left it in an 80188/186
  84.     mov    ax,86    ; No 1's, it's an 8088/86
  85.     jmp    DONE
  86. ;--------------------------------------------------------------------
  87. ; It's an 80188 or 80186...
  88. ;--------------------------------------------------------------------
  89. _18x:    mov    ax,186    ; Found a 1 in there somewhere, it's an 8018x
  90.  
  91. ;--------------------------------------------------------------------
  92. ; All done, let's go back...
  93. ;--------------------------------------------------------------------
  94. DONE:    popf        ; Restore the flag registers
  95.     ret
  96. ;--------------------------------------------------------------------
  97. ; End of code and segment
  98. ;--------------------------------------------------------------------
  99. _C_GETCPU endp
  100. _TEXT    ends
  101.     end    _C_GETCPU
  102.