unsigned long ReadCPUFreq(); 
/********************************************************************/ 
/**  function:     ReadCPUFreq                                     **/ 
/**  call:         ReadCPUFreq()                                   **/ 
/**  output:       Frequency of CPU, in Hz                         **/ 
/**  description:  the cpu frequency must < 4G                     **/ 
/********************************************************************/ 
unsigned long ReadCPUFreq() 

    unsigned long t1_lo, t1_hi; 
    unsigned long t2_lo, t2_hi; 
    unsigned long lo, hi, freq, freq1; 
    int    time = 1000; //Test time in ms 
  
   // Get Start Cycle Number 
   _asm{ 
        db 0fh,31h 
        db 66h 
        mov [WORD PTR t1_lo], ax 
        db 66h 
        mov [WORD PTR t1_hi], dx 
    } 
  
    // Delay some time 
    delay(time); 
  
    // Get Stop Cycle Number 
    _asm{ 
        db 0fh,31h 
        db 66h 
        mov [WORD PTR t2_lo], ax 
        db 66h 
        mov [WORD PTR t2_hi], dx 
    } 
  
    // Compute the frequency 
    hi   = t2_hi - t1_hi; 
    freq1  = (unsigned long)( hi * pow(2,32) / time * 1000.0 ); 
    if (t2_lo > t1_lo) { 
        lo = t2_lo - t1_lo; 
        freq = freq1 + (unsigned long)( lo * 1000.0 / time ); 
    } 
    else{ 
        lo = t1_lo - t2_lo; 
        freq = freq1 - (unsigned long)( lo * 1000.0 / time ); 
    } 
  
    return freq;