请问调用什么中断可以获取电脑时钟频率
想随机获取一些数,可以调用什么中断来获取电脑时钟频率?
转:利用Rdtsc指令计算CPU的时钟频率
; 文件名:Cpu.Asm; Dos下 .Com 格式文件
.model tiny
.586
.code
org 100h
start:
lea dx,Message ;显示信息
mov ah,9
int 21h
xor ax,ax
mov ds,ax
mov ebx,ds:[46ch] ;取时间,每55ms该值自动增1
rdtsc
mov esi,eax
mov edi,edx
mov ecx,ebx
bb:
cmp ecx,ds:[46ch]
jz bb
mov ecx,ds:[46ch]
rdtsc
push ecx
sub ecx,ebx
sub eax,esi
sbb edx,edi
push eax
push edx
mov eax,55000
mul ecx
mov ecx,eax
pop edx
pop eax
div ecx
call dispax
pop ecx
mov eax,ecx
sub eax,ebx
cmp ax,500 ;约30秒后自动退出
ja Over
mov ah,1 ;检测是否有按键
int 16h
jz bb
mov ah,0 ;有,则读按键
int 16h
Over:
mov ah,4ch ;程序结束
int 21h
; 显示AL代表的ASCII码字符
dispc proc NEAR
PUSH AX
PUSH DX
MOV AH,2
MOV DL,AL
INT 21H
POP DX
POP AX
RET
dispc endp
;以十进制的形式显示AX的值,显示所占的位数为CX
;若CX的值小于数据的实际宽度则按实际宽度输出
dispax proc near
push ax
push bx
push cx
push dx
push bp
mov cx,5 ;输出数据宽度5位
mov bx,0 ;记录数据实际宽度
mov bp,10 ;十进制
disp1:
xor dx,dx
div bp
inc bx ;显示数据的位数增1
push dx ;保存余数
cmp ax,0 ;商为0 ?
jnz disp1 ;没,继续!
sub cx,bx ;要求宽度和实际宽度比较
jle disp3
mov al,' ' ;宽度不够,前面补空格
disp2:
call dispc
loop disp2
disp3:
mov cx,bx ;数据的实际位数送CX
disp4:
pop ax ;依次从堆栈中取数并显示
and al,0fh
add al,'0'
call dispc
loop disp4
call SetPos
pop bp ;恢复寄存器的原值
pop dx
pop cx
pop bx
pop ax
ret
dispax endp
SetPos proc near ;调整光标位置
push ax
push dx
push ds
push cs
pop ds
lea dx,Back
mov ah,9
int 21h
pop ds
pop dx
pop ax
ret
SetPos endp
Even
Message db 13,10,'Press any key to STOP !',13,10,13,10
db 'Cpu Speed: MHz',8,8,8,8
Back db 8,8,8,8,8,'$'
end start
;--------------------------------------------------------------
编译链接
D:\Masm615>ml Cpu.asm
Microsoft (R) Macro Assembler Version 6.15.8803
Patched for you by promethee [ECL] in the year 2001 - enjoy
Copyright (C) Microsoft Corp 1981-2000. All rights reserved.
Assembling: Cpu.asm
Microsoft (R) Segmented Executable Linker Version 5.60.339 Dec 5 1994
Copyright (C) Microsoft Corp 1984-1993. All rights reserved.
Object Modules [.obj]: Cpu.obj /t
Run File []: "
List File [nul.map]: NUL
Libraries [.lib]:
Definitions File [nul.def]:
D:\Masm615>Cpu
Press any key to STOP !
Cpu Speed: 1000 MHz
D:\Masm615>_