I'm not a C/ASM developer and I would like to get current date and time from RTC with a Windows program.
Here, I found a C code to do this.
I changed that code in the following way, and I compiled it with Visual Studio 2017 cl.exe compiler without errors and warnings:
#include <stdio.h>
int main()
{
unsigned char tvalue, index;
printf("STARTING...\n");
for(index = 0; index < 128; index++)
{
__asm
{
cli /* Disable interrupts */
mov al, index /* Move index address */
/* since the 0x80 bit of al is not set, */
/* NMI is active */
out 0x70, al /* Copy address to CMOS register */
/* some kind of real delay here is probably best */
in al, 0x71 /* Fetch 1 byte to al */
sti /* Enable interrupts */
mov tvalue, al
}
printf("%u\n", (unsigned int)tvalue);
}
printf("FINISHED!\n");
return 0;
}
When I try to execute the exe from the command prompt, I don't see anything, only the row "STARTING...".
What am I doing wrong?
Thanks a lot.
The example code you found is operating system code, not Windows code. It would be sheer chaos if Windows allowed random processes to interact randomly with hardware devices like the real time clock. The operating system has a driver that talks to the real time clock and it won't allow processes to randomly poke into it.
As just the most obvious problem, you can't just disable interrupts from a process while a modern operating system is running!
I would like to get current date and time from RTC with a Windows program.
On Windows, you use Windows APIs (or wrappers)
The main APIs to read the system time are :
GetSystemTime
GetSystemTimePreciseAsFileTime
NtQuerySystemTime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With