如何获取双核CPU的序列号(100分)

  • 主题发起人 主题发起人 studyzyq
  • 开始时间 开始时间
S

studyzyq

Unregistered / Unconfirmed
GUEST, unregistred user!
使用下面这个函数获取的CPU序列号:
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;

每次取出来的序列号都不确定,有时候取到第一个CPU的,有时候又取到第二个CPU的.请问高手,[red]怎样指定取某个CPU的序列号都取出来,或者一次将两个CPU的序列号都读出来.[/red]
 
搜搜TCnCpuId?
 
function GetCPUID():string;
const
ID_BIT = $200000; // EFLAGS ID bit
type
TCPUID = array[1..4] of Longint;
TVendor = array [0..11] of char;

function IsCPUID_Available : Boolean; register;
asm
PUSHFD {direct access to flags no possible, only via stack}
POP EAX {flags to EAX}
MOV EDX,EAX {save current flags}
XOR EAX,ID_BIT {not ID bit}
PUSH EAX {onto stack}
POPFD {from stack to flags, with not ID bit}
PUSHFD {back to stack}
POP EAX {get back to EAX}
XOR EAX,EDX {check if ID bit affected}
JZ @exit {no, CPUID not availavle}
MOV AL,True {Result=True}
@exit:
end;

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;



var
CPUID : TCPUID;
I : Integer;
S : string;
begin
Result := '';
for I := Low(CPUID) to High(CPUID) do
CPUID := -1;

if IsCPUID_Available then
begin
CPUID := GetCPUID;
s :=IntToHex(CPUID[1],8);//CPUID是数组,这显示是第几个核心的
s :=s + '-' + copy(IntToHex(CPUID[2],8),3,6);
s :=s + '-' + IntToHex(CPUID[3],8);
s :=s + '-' + IntToHex(CPUID[4],8);
Result := s;
end
end;
 

Similar threads

I
回复
0
查看
502
import
I
I
回复
0
查看
854
import
I
I
回复
0
查看
637
import
I
I
回复
0
查看
547
import
I
后退
顶部