本文整理自网络,侵删。
unit CPU;
interface
uses
SysUtils;
type
TCPUID = array[1..4] of Longint;
TVendor = array[0..11] of char;
function GetCPUID: TCPUID; assembler; register;
function GetCPUVendor: TVendor; assembler; register;
function GetCPUInfo: string;
implementation
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;
function GetCPUInfo: string;
var
CPUID: TCPUID;
I: Integer;
S: TVendor;
begin
for I := Low(CPUID) to High(CPUID) do
CPUID[I] := -1;
CPUID := GetCPUID;
S := GetCPUVendor;
Result := S + IntToHex(CPUID[1],8) + IntToHex(CPUID[2],8)
+ IntToHex(CPUID[3],8) + IntToHex(CPUID[4],8);
end;
end.
相关阅读 >>
Delphi windows 编程[2] - 学习窗体生成的过程二
更多相关阅读请进入《Delphi》频道 >>