www.xbdev.net
xbdev - software development
Thursday December 26, 2024
Home | Contact | Support | Assembly Language What every pc speaks..1010...
>>
     
 

Assembly Language

What every pc speaks..1010...

 

Using rdtsc for timing in our code...




'rdtsc' is one of the Intel assembly instructions, which we can use to get the CPU tick-count.  It only takes a couple of asm instructions to get it, and we can use it to determine some basic runtime information if where in a hurry.

 

 

      int timeGetTime(void);

      #pragma aux timeGetTime = ".586" "rdtsc" value [eax] modify [edx];

 

 

Just take a looksy at that!  If only all small C snippets where that sweet.  BUT! There is a bit of a drawback if you don't have the 'WATCOM C/C++' compiler.... so I did a Visual C/C++ version as well :)

 

       int inline timeGetTime(void){   __asm{ rdtsc}  }

 

The rdtsc intel instruction, simply takes the tick count, which it keeps track on, deep within itself....and puts it into the eax register.  There are lots of useful intel asm intructions if you look around another example 'cpuid' which gives your CPU chip number....as each cpu chip has its own number given to it when its born.

 

 

Snippet : code.cpp (view)
 

int 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()

 

 

 

 

 

 

 

 

 

 

 

 

 

 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.