I cant seem to be able to use cpuid instruction.
I get the cant use in current cpu mode.

And is there any thing like the clock function
in C or C++?

Thank You
Bo Hunter
Posted on 2004-12-23 00:14:50 by bohunter11
Not sure what the clock function does but you can get the time stamp clock with RDTSC which gives the number of clocks since the last time the CPU was reset in EDX:EAX. If you are looking for the CPU speed (clocks/sec) I have a function in my system.lib library that does that pretty accurately, it's in GoAsm so you'll have to translate to MASM if that's what you use or you can just use the lib function directly in MASM with includelib and the supplied protos.

CPUSpeed FRAME

uses ebx,edi,esi
LOCAL hProcess :D
LOCAL hThread :D
LOCAL PriorityClass :D
LOCAL Priority :D
LOCAL timer :Q
LOCAL PerformanceCount :Q
LOCAL Frequency :Q

/*
Returns the number of clocks per second in EDX:EAX
*/

invoke GetCurrentProcess
mov [hProcess],eax
invoke GetCurrentThread
mov [hThread],eax
invoke GetPriorityClass,[hProcess]
mov [PriorityClass],eax
invoke GetThreadPriority,[hThread]
mov [Priority],eax

invoke QueryPerformanceFrequency,offset Frequency
or eax,eax
jnz >
invoke SetLastError,21
xor edx,edx
xor eax,eax
ret
:

mov esi,[Frequency]
mov edi,[Frequency+4]

invoke SetPriorityClass,[hProcess], REALTIME_PRIORITY_CLASS
invoke SetThreadPriority,[hThread], THREAD_PRIORITY_TIME_CRITICAL
invoke Sleep,0

invoke QueryPerformanceCounter,offset PerformanceCount
mov ebx,[PerformanceCount]

:
invoke QueryPerformanceCounter,offset PerformanceCount
mov eax,[PerformanceCount]
cmp ebx,eax
je <
add esi,eax
adc edi,[PerformanceCount+4]

ALIGN 4
rdtsc
mov [timer],eax
mov [timer+4],edx

:
invoke QueryPerformanceCounter,offset PerformanceCount
cmp edi,[PerformanceCount+4]
ja <
cmp esi,[PerformanceCount]
ja <

rdtsc
sub eax,[timer]
sbb edx,[timer+4]
push eax,edx

invoke SetThreadPriority, [hThread], [Priority]
invoke SetPriorityClass, [hProcess], [PriorityClass]
invoke SetLastError,0

pop edx,eax

or eax,eax
RET
ENDF
Posted on 2004-12-23 00:23:59 by donkey
For cpuid, use .586 instead
Posted on 2004-12-23 03:56:09 by roticv