C Interrupts concept
What are Interrupts?
- Interrupts are messages to the Pentium chip.
- Interrupt is used to halt current activity and perform our requested job.
- When we generate an interrupt, the CPU suspends it current operation.
- CPU performs the job we requested, finishes our job and resumes its suspended job.
- We are interrupting the CPU, that is why, we call it interrupts!
Explanation Of Interrupt :
- Suppose we have sample C Program to execute , Consider following code
- Then Current Program execution is halted and Control is given to the IO device i.e Keyboard to Enter the number.
- As soon as User Enters the number , the CPU resumes execution of the remaining code.
- The process of halting the Program execution in between is called interrupt.
int main() { int num1,num2,sum; printf("Enter the number 1 : "); scanf("%d",&num1); printf("Enter the number 2 : "); scanf("%d",&num2); sum = num1 + num2; printf("Sum : %d",sum); return(0); }
Above program is handed over to CPU for execution then CPU starts executing this program.While Executing Following Statement CPU is waiting for input from the user -
scanf("%d",&num1);