C Program to Demonstrate use of Interrupts in C Programming
Power of Interrupts :
- Interrupts are messages to the Pentium chip to halt it current activity, and perform our requested job.
- We can almost do anything using interrupts without using functions.
- Note below example - we haven’t used printf() still we are able to print message on screen.
Live Program :
1 2 3 4 5 6 7 8 9 | #include<dos.h> void main() { char *message = "Pritesh Taral$"; _AH = 9; _DX = (int) message; geninterrupt(0x21); } |
Output:
1 | Prtesh Taral |
Explanation of Program :
1 | #include<dos.h> |
- dos.h header file contain geninterrupt() function which is used to create interrupt.
- geninterrupt(0x21) is used to generate 0x21 interrupt.
- Note that the sentence is ended with a ‘$’ which is a terminating character.
- geninterrupt(0x21) means that we want to generate the 0x21 interrupt.
- The ‘0x’ prefix is given which tells that the number is in hexadecimal.
- There are many interrupts, each having its own unique number.
1 | _AH = 9 |
- We want to fill the register AH with integer 9.
- Register is actually a memory location inside your Pentium chip.
1 | _DX=(int)message |
- We are storing the address of the message to register DX.