来源:www.cncfan.com | 2006-3-27 | (有4360人读过)
//获得CPU类型 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;
//获得CPU主频 function GetCPUSpeed: Double; const DelayTime = 500; // measure time in ms var TimerHi, TimerLo: DWORD; PriorityClass, Priority: Integer; begin PriorityClass := GetPriorityClass(GetCurrentProcess); Priority := GetThreadPriority(GetCurrentThread);
SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
Sleep(10); asm dw 310Fh // rdtsc mov TimerLo, eax mov TimerHi, edx end; Sleep(DelayTime); asm dw 310Fh // rdtsc sub eax, TimerLo sbb edx, TimerHi mov TimerLo, eax mov TimerHi, edx end;
SetThreadPriority(GetCurrentThread, Priority); SetPriorityClass(GetCurrentProcess, PriorityClass);
Result := TimerLo / (1000.0 * DelayTime); end;
|