- 论坛徽章:
- 0
|
下载一本书的时候正好翻到,里面利用8253做汇编代码的性能测试,其中提到
Finally, timer 0 is used to drive the system clock. As programmed by the BIOS at power-up, every 65,536 (64 K) counts, or 54.925 milliseconds, timer 0 generates a rising edge on its output line. (A millisecond is one-thousandth of a second, and is abbreviated ms). This line is connected to the hardware interrupt 0 (IRQ0) line on the system board, so every 54.925 ms timer 0 causes hardware interrupt 0 to occur.
The interrupt vector for IRQ0 is set by the BIOS at power-up time to point to a BIOS routine, TIMER_INT, that maintains a time-of-day count. TIMER_INT keeps a 16-bit count of IRQ0 interrupts in the BIOS data area at address 0000:046C (all addresses are given in segment ffset hexadecimal pairs); this count turns over once an hour (less a few microseconds), and when it does, TIMER_INT updates a 16-bit hour count at address 0000:046E in the BIOS data area. This routine is the basis for the current time and date that DOS supports via functions 2Ah (2A hexadecimal) through 2Dh and by way of the DATE and TIME commands.
看来*clock就是bios保存的每秒18.2次的那个tick计数的低16位
不过这代码好象有问题啊
应该是16位的dos编译器吧,假设clicks=2,now=65535,*clock回绕到0的时候,虽然避免了陷入长达1小时的delay,但是循环却提前结束了
另外,clock指针应该声明为volatile吧,否则编译器有可能把while优化成死循环 |
|