.model small .586 .stack 100h .data msg1 db "CPU supports timestamp counter.",0dh, 0ah,"$" msg2 db "CPU does NOT support timestamp counter.",0dh, 0ah,"$" msg3 db "CPU timer is enabled.",0dh, 0ah,"$" msg4 db "CPU timer is disabled!!!!.",0dh, 0ah,"$" msg5 db "Attempt to enable counter FAILED. Counter still disabled.",0dh, 0ah,"$" msg6 db "Attempt to enable counter SUCCEEDED. Counter is enabled.",0dh, 0ah,"$" msg7 db "Testing timer via read -- pausing....",0dh, 0ah,"$" msg8 db "If you see this msg, then timer worked.",0dh, 0ah,"$" dtime dw 2000 ;; wait time in milliseconds itimelow dd 0 ;; used by delay routine itimehigh dd 0 .code ;program will test to see if this CPU has a timestamp counter main proc mov ax,@data mov ds,ax mov eax, 1h ; get feature information cpuid ;get CPU id test dl,00010000b ; check status bit jz bad ;; timer is supported mov dx, offset msg1 mov ah,09h int 21h ;; see if timer is enabled mov eax, cr4 ; read control register 4 test al, 00000100b ; check disable bit jnz bad2 ;; timer is enabled mov dx, offset msg3 mov ah,09h int 21h jmp exit bad2: mov dx, offset msg4 ; print disabled msg mov ah,09h int 21h ;; try to enable counter mov eax, cr4 and al, 11111011b ; clr bit 2 mov cr4,eax ;now check to see this succeeded mov eax, cr4 ; read control register 4 test al, 00000100b ; check disable bit jnz bad3 mov dx, offset msg6 mov ah,09h int 21h mov dx, offset msg7 mov ah,09h int 21h mov cx,dtime ;; get time to wait call mywait ; try timer mov dx, offset msg8 mov ah,09h int 21h jmp exit bad3: mov dx, offset msg5 mov ah,09h int 21h jmp exit bad: mov dx, offset msg2 mov ah,09h int 21h exit: Mov ax, 4c00h ;exit Int 21h main endp CLKFREQ EQU 800 ;; clock frequency in MHZ TICS_MS EQU CLKFREQ*1000 ;; will delay # of milliseconds specified in CX. Register CX destroyed mywait proc push eax push edx mywaitlp2: call timget mov itimelow,eax mov itimehigh,edx mywaitlp1: call timget sub eax,itimelow sbb edx,itimehigh ;; edx:eax has delta time. Compare to TICS_MS sub eax,tics_ms sbb edx,0 jc mywaitlp1 loop mywaitlp2 pop edx pop eax ret mywait endp ;;; procedure that returns the Pentium+ 64 bit timer value ;;; in EDX:EAX timget proc rdtsc ;; read timestamp counter ret timget endp end main