任何获得CPU的序列号?(50分)

  • 主题发起人 主题发起人 比尔.丐痴
  • 开始时间 开始时间

比尔.丐痴

Unregistered / Unconfirmed
GUEST, unregistred user!
type
TCPUID = array[1..4] of Longint;

function GetCPUID : TCPUID; assembler; register; //得到CPU序列号
asm
PUSH EBX {Save affected register}
PUSH EDI
MOV EDI,EAX {@Resukt}
MOV EAX,1
DW $A20F {CPUID Command}
STOSD {CPUID[1]}
MOV EAX,EBX
STOSD {CPUID[2]}
MOV EAX,ECX
STOSD {CPUID[3]}
MOV EAX,EDX
STOSD {CPUID[4]}
POP EDI {Restore registers}
POP EBX
end;
 
摘 要:如何检测CPU的型号
关键字:CPU 微处理器 微 处理器 检测 型号
类 别:系统控制


CoDelphi.com版权所有,未经允许,不得进行任何形式转载


Unit CPUid;

Interface

Type
TCpuType = (cpu8086, cpu286, cpu386, cpu486, cpuPentium);

Function CpuType : TCpuType;
Function CpuTypeString : String;

Implementation

Uses
SysUtils;

Function CpuType : TCpuType; ASSEMBLER;
Asm
// 8086 CPU 检测
push ds
pushf
pop bx
mov ax, 0fffh
and ax, bx
push ax
popf
pushf
pop ax
and ax, 0f000h
cmp ax, 0f000h
mov ax, cpu8086
je @@End_CpuType
// 80286 CPU检测
or bx, 0f000h
push bx
popf
pushf
pop ax
and ax, 0f000h
mov ax, cpu286
jz @@End_CpuType
// 386 CPU 检测
db 66h
pushf
db 66h
pop ax
db 66h
mov cx, ax
db 66h
xor ax, 0h
dw 0004h
db 66h
push ax
db 66h
popf
db 66h
pushf
db 66h
pop ax
db 66h
xor ax, cx
mov ax, cpu386
je @@End_CpuType
// 486 CPU 检测
db 66h
pushf
db 66h
pop ax
db 66h
mov cx, ax
db 66h
xor ax, 0h
dw 0020h
db 66h
push ax
db 66h
popf
db 66h
pushf
db 66h
pop ax
db 66h
xor ax, cx
mov ax, cpu486
je @@End_CpuType
// Pentium CPU 检测
db 66h
mov ax, 1
dw 0
db 66h
db 0Fh
db 0a2h
db 66h
and ax, 0F00H
dw 0
db 66h
shr ax, 8
sub ax, 1
@@End_CpuType:
pop ds

End;

Function CpuTypeString : String;

Var
Kind : TCpuType;

Begin
Kind := CpuType;
Case Kind Of
cpu8086 : Result := '8086';
cpu286 : Result := '286';
cpu386 : Result := '386';
cpu486 : Result := '486';
cpuPentium : Result := 'Pentium';
Else Result := Format ('P%d', [Ord (kind)]);
End;

End;

End.
 
谢谢大家支持,已经解决了,在这得到maming的帮助,在此表示感谢!下面是maming提供的源码.
unit Main;
interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons;

type
TDemoForm = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Bevel1: TBevel;
Label5: TLabel;
procedure BitBtn1Click(Sender: TObject);
end;

var
DemoForm: TDemoForm;

implementation

{$R *.DFM}

type
TCPUID = array[1..4] of Longint;
TVendor = array [0..11] of char;

function GetCPUID : TCPUID; assembler; register;
asm
PUSH EBX {Save affected register}
PUSH EDI
MOV EDI,EAX {@Resukt}
MOV EAX,1
DW $A20F {CPUID Command}
STOSD {CPUID[1]}
MOV EAX,EBX
STOSD {CPUID[2]}
MOV EAX,ECX
STOSD {CPUID[3]}
MOV EAX,EDX
STOSD {CPUID[4]}
POP EDI {Restore registers}
POP EBX
end;

function GetCPUVendor : TVendor; assembler; register;
asm
PUSH EBX {Save affected register}
PUSH EDI
MOV EDI,EAX {@Result (TVendor)}
MOV EAX,0
DW $A20F {CPUID Command}
MOV EAX,EBX
XCHG EBX,ECX {save ECX result}
MOV ECX,4
@1:
STOSB
SHR EAX,8
LOOP @1
MOV EAX,EDX
MOV ECX,4
@2:
STOSB
SHR EAX,8
LOOP @2
MOV EAX,EBX
MOV ECX,4
@3:
STOSB
SHR EAX,8
LOOP @3
POP EDI {Restore registers}
POP EBX
end;

procedure TDemoForm.BitBtn1Click(Sender: TObject);
var
CPUID : TCPUID;
I : Integer;
S : TVendor;
begin
for I := Low(CPUID) to High(CPUID) do CPUID := -1;
CPUID := GetCPUID;
Label1.Caption := 'CPUID[1] = ' + IntToHex(CPUID[1],8);
Label2.Caption := 'CPUID[2] = ' + IntToHex(CPUID[2],8);
Label3.Caption := 'CPUID[3] = ' + IntToHex(CPUID[3],8);
Label4.Caption := 'CPUID[4] = ' + IntToHex(CPUID[4],8);
S := GetCPUVendor;
Label5.Caption := S;
end;

end.
 
多人接受答案了。
 
后退
顶部