home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
borland
/
jnfb88.arc
/
GETCPU.ARC
/
C_GETCPU.ASM
< prev
next >
Wrap
Assembly Source File
|
1987-09-21
|
5KB
|
102 lines
name C_GETCPU
page 55,132
title "C_GETCPU -- Determines Which INTEL CPU is Installed"
;--------------------------------------------------------------------
; This program determines which INTEL CPU is being used in the
; machine, whether it is an 8088/86, 80188/186, 80286 or 80386.
; It uses documented and supported differences in flag register bit
; configurations to determine whether the CPU is an 80286 or 80386,
; and differences in shifting using CL to determine if it is an
; 8088/86 or 80188/186. It is intended to be used as an external
; routine from Turbo C, and returns an integer result in the form
; the last three digits of the processor type, as depicted in the
; table below. This code is designed for the TINY/SMALL modem.
; See page 254 of the Turbo C User's Guide for information on how
; to modify this routine for other memory models.
;
; If the processor is The routine returns
; ------------------- -------------------
; 80386 386
; 80286 286
; 80188/186 186
; 8088/86 86
;
;--------------------------------------------------------------------
; Declaration of the routine in Turbo C is:
;
; int C_GETCPU();
;
;--------------------------------------------------------------------
; To assemble:
;
; MASM C_GETCPU,,,;
;
;--------------------------------------------------------------------
; Code segment begins here
;--------------------------------------------------------------------
; Required by Turbo C for small memory model
_TEXT segment byte public 'CODE'
assume cs:_TEXT ; Ditto
;--------------------------------------------------------------------
; Actual ID routine begins here
;--------------------------------------------------------------------
public _C_GETCPU ; Make sure Turbo C can get here
_C_GETCPU proc near ; Entry point for the subroutine
pushf ; Save flag registers, we use them here
xor ax,ax ; Clear AX and...
push ax ; ...push it onto the stack
popf ; Pop 0 into flag registers (all bits to 0),
pushf ; attempting to set bits 12-15 of flags to 0's
pop ax ; Recover the save flags
and ax,08000h ; If bits 12-15 of flags are set to
cmp ax,08000h ; zero then it's 8088/86 or 80188/186
jz _8x_18x
;--------------------------------------------------------------------
; It is either an 80286 or an 80386, let's find out which...
;--------------------------------------------------------------------
mov ax,07000h ; Try to set flag bits 12-14 to 1's
push ax ; Push the test value onto the stack
popf ; Pop it into the flag register
pushf ; Push it back onto the stack
pop ax ; Pop it into AX for check
and ax,07000h ; if bits 12-14 are cleared then
jz _286 ; the chip is an 80286
;--------------------------------------------------------------------
; Ok, we know it's an 80386 now, tell the user about it!
;--------------------------------------------------------------------
mov ax,386 ; It's not a 286, so it must be an 80386
jmp DONE ; (at least until the 80486 comes out...)
;--------------------------------------------------------------------
; Tell the user it's an 80286
;--------------------------------------------------------------------
_286: mov ax,286 ; Get the msg ready
jmp DONE ; Bye
;--------------------------------------------------------------------
; We know it is either an 8088/86 or 80188/86, but which one is it?
;--------------------------------------------------------------------
_8x_18x:
mov ax,0FFFFh ; Set AX to all 1's
mov cl,33 ; Now we try to shift left 33 time. If it's
shl ax,cl ; an 808x it will shift it 33 times, if it's
; an 8018x it wil only shift one time
jnz _18x ; Shifting 33 times would have left all 0's
; if any 1's are left it in an 80188/186
mov ax,86 ; No 1's, it's an 8088/86
jmp DONE
;--------------------------------------------------------------------
; It's an 80188 or 80186...
;--------------------------------------------------------------------
_18x: mov ax,186 ; Found a 1 in there somewhere, it's an 8018x
;--------------------------------------------------------------------
; All done, let's go back...
;--------------------------------------------------------------------
DONE: popf ; Restore the flag registers
ret
;--------------------------------------------------------------------
; End of code and segment
;--------------------------------------------------------------------
_C_GETCPU endp
_TEXT ends
end _C_GETCPU