// main.cpp

// www.xbdev.net

// bkenwright@xbdev.net

// Code -> "it should be fun"

#include <stdio.h> // for printf(..)

/*
asm 
        xor eax,eax 
        xor ebx,ebx 
        xor ecx,ecx 
        xor edx,edx 
        db $0F,$A2                /// cpuid 
        db $0F,$31                /// rdtsc 
        mov StartTicks,eax 
       end; 

*/


/*
// Watcom C/C++
int timeGetTime(void);
#pragma aux timeGetTime = ".586" "rdtsc" value [eax] modify [edx];
*/

// Visual Studio C/C++
/*
int timeGetTime(void)
{
	__asm
	{
		;xor eax,eax   ; clear eax
		;xor ebx,ebx   ; clear ebx
		;xor ecx,ecx   ; clear ecx
		;xor edx,edx   ; clear edx
		rdtsc         ; put tick count into eax
		              ; db 0x0F, 0x31
					  ; Just to note here, cpuid is 0x0F, 0xA2
	}// end asm block

}// End timeGetTime(..)
*/

int inline timeGetTime(void){   __asm{ rdtsc}  }

// Program entry point
void main()
{

	int t, i;
	printf("CPU Ticks %d \n", t = timeGetTime() );

	printf("<small delay (100)>\n");
	for( i=0; i<100; i++) ;

	printf("(Difference in)CPU Ticks %d \n", timeGetTime()-t );

}// end main()













