# Difference between ISR and Function Call

In this article, you will learn about the difference between the ISR and function call, but before discussing the differences, you have to know about the ISR and function call in brief.

### What is ISR?

An interrupt service routine (ISR) is a software routine that hardware invokes in response to an interrupt. ISR examines an interrupt, determines how to handle it, executes it, and returns a logical interrupt value. If no further handling is required, the ISR notifies the kernel with a return value. An ISR must perform very quickly to avoid slowing down the operation of the device and the operation of all lower-priority ISRs.

Although an ISR might move data from a CPU register or a hardware port into a memory buffer, generally, it relies on a dedicated interrupt thread (or task), called the interrupt service thread (IST), to do most of the required processing. If additional processing is required, the ISR returns a logical interrupt value to the kernel. Then it maps a physical interrupt number to a logical interrupt value.

### Mechanism of Interrupt Handling

Below is the mechanism of interrupt handling in the following steps, such as:

• An interrupt is a condition that makes the CPU suspend the current program and execute an ISR. An ISR is a specially written program to service the condition that caused the interrupt.
• After an interrupt is serviced, the CPU returns to the main program, exactly at the next instruction where it had left.
• In interrupt-driven data transfer, whenever the I/O device is ready for the data transfer, it will interrupt the CPU. In the ISR, the CPU will perform the data transfer.
• This method is better than polling because the CPU does not have to waste time in checking the status of the I/O device. A keyboard is a good example of interrupt-driven I/O access.
• Instead of checking the CPU, the keyboard should interrupt the CPU when a key is pressed. Thus time will not be wasted in repeatedly checking the keyboard when the user is not typing at all.
• The I/O device requests an interrupt by sending the $\overline{INTR}$ signal to the CPU.
• Whenever CPU receives $\overline{INTR}$ signal, it completes the execution of the current instruction and then executes the ISR. When the CPU is ready, then it sends acknowledge signal through the INTA line.
• ISR gets executed, and the CPU returns to the main program.
• I/O devices turn off the $\overline{INTR}$ signal after execution.

For Example: In the below example, I/O transfer by interrupt-driven I/O.

• If an I/O device that wants to perform a data transfer with the processor must interrupt the processor.
• An interrupt is a condition that makes the processor executes an Interrupt Service Routine.
• In the ISR, the processor will perform data transfer with the I/O device.

In this example, interrupt request by pressing the keyboard key,

• Instead of the processor checking whether a key is pressed, the keyboard interrupts the processor when pressing a key.
• In the ISR of the keyboard, which is a part of the keyboard driver software, the processor will read the data from the keyboard.

Below are the following advantages of ISR, such as:

• ISR asynchronous events can occur at any time during the program's execution.
• ISR saves the PC, Flags, and registers on the stack, disables all the interrupts, and loads the address of the ISR.
• ISR cannot have arguments that can be passed to it.
• ISR cannot return values.
• ISR enables the interrupts.
• Generally, ISR is small as it takes some other process's time.
• Some of ISR have their own stack.

### What is Function Call?

A function call is also called a subroutine call. A subroutine is a set of instructions needed repeatedly by the program. It is part of a larger program that is responsible for carrying out a specific task. The larger program may execute a heavy workload, and the subroutine may be performing just a simple task, which is also independent of the remaining program coding.

A function is coded in such a way that it may be called multiple times and from different places (even from within other functions). When a function is called, the processor may go to where the code for the function is residing and execute the instructions of the function one by one. After completing the functions, the processor will return to exactly where it left off and continue the execution starting from the next instruction.

Functions are a great tool for code reuse. Many modern programming languages support functions. A collection of functions is called a library. Libraries are often used as means of sharing and trading software. In some cases, the whole program could be a sequence of subroutines.

In the case of an 8086 processor, a subroutine is invoked by a CALL instruction, and control returns by a RET instruction. It reduces the size of the program.

### Difference between ISR and Function Call

A function must be explicitly called and is part of the same context and thread of execution as its caller. A hardware ISR is not explicitly called but rather invoked by some external event. The current thread's context is automatically preserved when an interrupt is called before switching context to the ISR.

In return, the reverse context switch occurs, restoring the state of the processor before the interrupt so that execution continues from the point of interruption. Below are some more differences between ISR and function call.

ISR Function Call
The interrupt is usually initiated by an internal or an external signal microprocessor rather than the execution of instructions. The ISR is executed after storing the program's current status in the stack.
ISR performs different tasks depending on the interrupted device or instructions written by a programmer.
The function call is invoked by executing instructions, which perform the specific tasks and reduce the program's size.
The hardware determines the address of the ISR.
The ISR address is written inside the interrupt vector table, and the ISR address for each interrupt is fixed.
The address of the subroutine is written inside the instruction, which is written inside the main program code.
When an interrupt occurs during the execution of a current program, therefore, after the execution of the current instruction, the processor executes ISR. After the execution of ISR, the processor must resume the program exactly as before the interrupt occurred.
For this, the PC content, µP registers, and some status conditions are stored. The collection of all status bit conditions in a microprocessor is called PSW (program status word).
• During the interrupt cycle, the contents of the PC and PSW are pushed onto the stack. The branch address for the particular interrupt is then passed to PC, and a new PSW is loaded into the status register.
• The last instruction in the ISR is the return from interrupted instruction. When this instruction is executed, the old PSW and the return address are popped from the stack.
Here, only a PC is stored on the stack to get the address of the next instruction in the main program.
The subroutine must have access to data from the calling subroutine and return results to that subroutine. Therefore, subroutine parameters and data linkage is done.
This can be done through
• The AC register can be used for a single input parameter and a single output parameter. In computers with multiple processor registers, more parameters can be passed this way.
• Another way to pass data to a subroutine is through memory.