[C] 屏蔽中断 →→→→→进入此内容的聊天室

来自 , 2019-10-07, 写在 C, 查看 122 次.
URL http://www.code666.cn/view/4aecfbe5
  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <conio.h>
  4.  
  5. #define INTR 0X1C    /* The clock tick
  6. interrupt */
  7.  
  8. void interrupt ( *oldhandler ) ( void );
  9.  
  10. int count=0;
  11.  
  12. void interrupt handler ( void )
  13. {
  14.         /* disable interrupts during the handling of
  15.            the interrupt */
  16.         disable();
  17.         /* increase the global counter */
  18.         count++;
  19.         /* reenable interrupts at the end of the
  20.            handler */
  21.         enable();
  22.         /* call the old routine */
  23.         oldhandler();
  24. }
  25.  
  26. int main ( void )
  27. {
  28.         /* save the old interrupt vector */
  29.         oldhandler = getvect ( INTR );
  30.  
  31.         /* install the new interrupt handler */
  32.         setvect ( INTR, handler );
  33.  
  34.         /* loop until the counter exceeds 20 */
  35.         while ( count < 20 )
  36.                 printf ( "count is %d\n",count );
  37.  
  38.         /* reset the old interrupt handler */
  39.         setvect ( INTR, oldhandler );
  40.  
  41.         return 0;
  42. }

回复 "屏蔽中断"

这儿你可以回复上面这条便签

captcha