Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!mips!ultra!srini From: srini@ultra.com (S. Srinivasan) Newsgroups: comp.os.msdos.programmer Subject: Re: MSC, interrupts & functions Message-ID: <1990Sep28.171700.3308@ultra.com> Date: 28 Sep 90 17:17:00 GMT References: <8539@helios.TAMU.EDU> <10850002@hp-ptp.HP.COM> Organization: Ultra Network Technologies Lines: 60 >I have successfully written a program that uses interrupt 1Ch to beep >the speaker every few seconds. However, after trying to spruce it up >I have noticed that functions called by an interrupt (declared void >interrupt far) cannot call other functions declared simply void or int. > > The one thing to watch out for is that you do not overextend yourself in doing things in interrupt mode. Some of the reasons for this are: 1. some library calls may not be re-entrant. For example, a call to print something would issue another interrupt to DOS. If this print were called from within an interrupt vector, then you have an interrupt within an interrupt. Which may not be too bad, but if you don't know the OS, then dont mess with it. 2. You might be blowing your stack if interrupts nest or if you are making other function calls from your interrupt vector. Your default stack with MSC is 2K. Generally enough, but ... The solution in a single-tasking system like DOS is simple but crude. This is recommended for those who dont know DOS too well, (like me!). main() { char int_happened = FALSE; while (TRUE) { if (int_happened) { beep(); int_happened = FALSE; } } } /* No longer invoked in interrupt-mode */ void beep() { printf("beep\n"); } /* Does not call any other functions */ void interrupt far count() { if (cbeep_count > beep_count) { int_happened = TRUE; cbeep_count = 0; /* reset counter */ } else ++cbeep_count; } Depending on how your code is structured, you may not have to loop on this 'int_happened' variable everywhere in your code, but ...! srini@ultra.com