format PE GUI 4.0
entry start
include 'win32a.inc'
section '.import' import data readable executable
library kernel32, 'KERNEL32.DLL',\
user32, 'USER32.DLL',\
msvcrt, 'MSVCRT.DLL'
import kernel32,\
ExitProcess,'ExitProcess',\
GetModuleHandle,'GetModuleHandleA',\
SetPriorityClass,'SetPriorityClass',\
GetCurrentThread,'GetCurrentThread',\
SetThreadPriority,'SetThreadPriority',\
QueryPerformanceFrequency,'QueryPerformanceFrequency',\
QueryPerformanceCounter,'QueryPerformanceCounter'
import user32,\
MessageBox,'MessageBoxA',\
wsprintf,'wsprintfA'
import msvcrt,\
sprintf,'sprintf'
section '.udata' readable writeable
Frequency dq ?
Counter1 dq ?
Counter2 dq ?
Difference dq ?
Time dq ?
Speed dq ?
nval dd ?
Text db 256 dup (?)
section '.code' code readable writeable executable
Cpuspeed db "Cpu Speed",0
NoHPC db "This system doesn't support a high performance counter. Application will now quit.",0
Starttext db "ECX register will be decreased 2^32 times using loop method.",10,"For most reliable results, please close down all running applications,",10,"avoid user inputs during process, even mouse motions.",10,"If possible, disable network interfaces and connections.",10,10,"Click OK to start.",0
Endtext db "Performance Counter Frequency: %I64d Hz.",10,"Counted Ticks: %I64d",10,10,"Time Passed: %I64d ns.",10,10,"Cpu Speed: %I64d Hz.",0
start:
invoke GetModuleHandle, NULL
invoke SetPriorityClass, eax, REALTIME_PRIORITY_CLASS
invoke GetCurrentThread
invoke SetThreadPriority, eax, THREAD_PRIORITY_TIME_CRITICAL
invoke QueryPerformanceFrequency, Frequency
cmp eax, 0
jne @F
invoke MessageBox, NULL, NoHPC, Cpuspeed, NULL
jmp quit
@@:
invoke MessageBox, NULL, Starttext, Cpuspeed, NULL
invoke QueryPerformanceCounter, Counter1
mov ecx, 0h
@@: loop @B
invoke QueryPerformanceCounter, Counter2
movq mm0, [Counter2] ; Using SSE instructions.
psubq mm0, [Counter1]
movq [Difference], mm0
emms
;mov eax, dword [Counter2]
;mov ecx, dword [Counter2 + 4]
;sub eax, dword [Counter1]
;sbb ecx, dword [Counter1 + 4]
;mov dword [Difference], eax
;mov dword [Difference + 4], ecx
fild [Difference]
fild [Frequency]
fdivp st1, st0
mov [nval], 1000000000
fimul [nval]
fistp [Time]
fild [Time]
mov [nval], 16
fidiv [nval]
mov [nval], 1000000000
fidiv [nval]
mov [nval], 20000000h
fidiv [nval]
fld1
fdiv st0, st1
fistp [Speed]
invoke sprintf, Text, Endtext, dword [Frequency], dword [Frequency+4], dword [Difference], dword [Difference+4], dword [Time], dword [Time+4], dword [Speed], dword [Speed+4]
invoke MessageBox, NULL, Text, Cpuspeed, NULL
quit:
invoke ExitProcess, 0