microsoft c isr question

Gerry Wiener wiener at stout.UCAR.EDU
Sun Feb 18 11:21:47 AEST 1990


In the following code an interrupt handler for the keyboard is
replaced by one that increments a counter then chains to the original
handler.  Question:  Why doesn't "count" get incremented correctly?
Please mail me the replies.

	Gerry Wiener	  Email:wiener at stout.ucar.edu

------------------------------------------------------------------------

#include <dos.h>
#include <stdio.h>

#define KEYBD  0x16

void (interrupt far *oldkb)(void);
void interrupt far newkb(void);
int count;

main()
{
  int c;

  oldkb = _dos_getvect(KEYBD);

  _dos_setvect(KEYBD, newkb);

  count = 0;
  while ((c = getchar()) != 'x')
    {
      printf("count is %d\n", count);
      putchar(c);
    }
  _dos_setvect(KEYBD, oldkb);
}

void interrupt far newkb(void)
{
  count++;
  _chain_intr(oldkb);
}




More information about the Comp.lang.c mailing list