Computer Science, asked by Atom1493, 1 year ago

Difference between subroutine and interrupt in computer organization

Answers

Answered by saitejassb
37
Subroutine is a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code. 
Interrupt Service Routines (ISRs) are to handle hardware interrupts. These routines are not independent threads, but more like signals. ISR is called if any thread is suspended by an interrupt

Subroutine runs when you call it. ISR runs whenever a certain signal occurs. (The signal can be generated by software or hardware.) The big difference is that you know where the subroutine runs (because you call it). But you do not know when the ISR will be executed. You code may run normally when an hardware interrupt occurs and your program jumps to the ISR. This can happen anywhere in your code (in between two statements or even in the middle of a complete statement, remember a statement is compiled into multiple assembly instructions).

Therefore, cares must be taken when ISR accesses global variables. Race condition may occur if ISR and a normal thread touches the same global variable at the same time
Simply, a subroutine is code you write and call as required, an interrupt is system bound and cannot be called by the user but occurs when something happens (sources are hardware, software and CPU) that requires immediate attention.
You write subroutines to handle interrupts in
Answered by Anonymous
33

Subroutine vs. Interrupt

Subroutine:

  • Subroutine is function that runs when you call it.
  • It is a small code within a big piece of code.
  • It is usually independent of the big piece of code.

Interrupt:

  • Interrupt occurs automatically in between whenever a certain condition is met.
  • These are designed to handle hardware interrupts.
  • They are not a piece of code rather more like signals.
Similar questions