Fab*_*zio 3 c windows assembly real-time-clock
我不是C / ASM开发人员,我想使用Windows程序从RTC获取当前日期和时间。
在这里,我找到了执行此操作的C代码。
我以以下方式更改了该代码,并使用Visual Studio 2017 cl.exe编译器对其进行了编译,没有错误和警告:
#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;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试从命令提示符下执行exe时,什么都没有,只有“ STARTING ...”行。
我究竟做错了什么?
非常感谢。
您找到的示例代码是操作系统代码,而不是Windows代码。如果Windows允许随机进程与诸如实时时钟之类的硬件设备进行随机交互,那将是一片混乱。操作系统有一个与实时时钟对话的驱动程序,它不允许进程随机进入该时钟。
作为最明显的问题,您不能仅在现代操作系统运行时就禁用进程中断!