How we can implement our own timer function in Windows without using Library functions? Should we deal with assembly language instructions?
This depends on the precision and resolution you require.
Assuming you need more than second precision, it's popular to wrap/use the RDTSC
instruction. But you can also just use the Win32 API, the QueryPerformanceCounter()
is widely used for this.
Many APIs like Intel's Threading Building Blocks (http://threadingbuildingblocks.org), OpenMP (http://openmp.org), SDL (http://libsdl.org) or SFML (http://sfml-dev.org), and I think also OpenGL (http://opengl.org) implement a timer or a wrapper around a timer.
Saying "without using Library functions" is a bit vague: Which library do you mean specifically? In the end, you have to use some library function, or inline assembly, because C++ doesn't have timing functionality in the core language. And without any timer processor or some other timing hardware in whichever form (*), there is no way to tell the time, not vaguely, not exactly.
(*) That includes internet time providers.
Disclamer: please don't ever use code like this
typedef long time_t;
time_t time(time_t *);
int printf(const char * __restrict, ...);
int main()
{
printf("%d\n", time(0));
}
is a complete program that compiles with just 'gcc foo.c'
It uses the standard library, but I'm not sure it's possible to do anything without it. For further entertainment, it does it without header files (warning: this will break much compatibility)
it gives only second resolution, but you get the idea.
get the atomclock time from an internet time service.
else you will always deal with some sort of library-functions with which you can talk to the BIOS, which is the part that makes the tick-tock from the Quartz visible to the OS.