-
-
汇编取CPU频率-- 没效果??
-
发表于:
2010-5-10 14:14
4220
-
.586p
.model flat,stdcall
option casemap:none
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\windows.inc
;计算CPU频率
;使用如下变量
.data
hProcess dd ? ;当前进程的句柄
hThread dd ? ;当前线程句柄
oldPrioClass dd ? ;当前线程的prioclass
oldPrio dd ? ;当前线程prio
theLoword dd ? ;时间戳
theHighWord dd ? ;时间戳到High
szBuffer dd ?
.code
start:
invoke GetCurrentProcess ;获取进程句柄
mov hProcess , eax ;存值
invoke GetPriorityClass,hProcess ;得到进程的优化级
mov oldPrioClass,eax ;句柄存
invoke GetThreadPriority, hThread ;线程优先级.
mov oldPrio,eax ; 存值
;转换程序为优先级
invoke SetPriorityClass,hProcess,REALTIME_PRIORITY_CLASS ;相当于100h
invoke SetThreadPriority,hThread,THREAD_PRIORITY_TIME_CRITICAL ;等于 0Fh
invoke Sleep,10 ;延时
RDTSC ;取时间戳
mov theLoword,eax
mov theHighWord,edx
invoke Sleep ,500 ;延时0.5秒
RDTSC ;取时间戳
sub eax,theLoword ;theloword=theloword-new loword
sbb edx,theHighWord ;带位减法
mov theLoword,eax ;新值存放
mov theHighWord,edx
invoke SetThreadPriority,hThread,oldPrio ;设置线程的优先级
invoke SetPriorityClass,hProcess,oldPrioClass ;设置进程的优先级
;本计算基于上述第二个Sleep函数
;CPU 频率=Loword / (1000*延时)
mov eax,theLoword
xor edx,edx
mov ebx,500000
div ebx
mov szBuffer ,eax
invoke MessageBox ,NULL,addr szBuffer,addr szBuffer,MB_OK
end start
照网上的代码来了一遍,结果是得出CPU频率的例子....
编译通过,运行看不到频率哦,怎么回事?
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!