What is the Difference Between Hardware and Software Interrupt

The main difference between hardware and software interrupt is that a hardware interrupt is generated by an external device while a software interrupt is generated by an executing program.

An interrupt is an event that occurs by a component of a device other than the CPU. It indicates the CPU that it should take immediate action. Network devices, timers, etc. can cause interrupts. However, most modern computers can handle interrupts faster. Moreover, there are two main types of interrupts as hardware and software interrupt. We will be discussing here these two types of interrupts and thereby discern the difference between hardware and software interrupt.

Key Areas Covered

1. What is Hardware Interrupt
     – Definition, Functionality
2. What is Software Interrupt
     – Definition, Functionality
3. What is the Difference Between Hardware and Software Interrupt
     – Comparison of Key Differences

Key Terms

Interrupt, Hardware Interrupt, Kernel, Maskable Interrupt, Non-Maskable Interrupt, Software Interrupt

Difference Between Hardware and Software Interrupt - Comparison Summary

What is Hardware Interrupt

Hardware devices generate hardware interrupts. A hard disk can generate a hardware interrupt to inform that it has read a series of data blocks. A network device can create a hardware interrupt to indicate that it received data packets. Moreover, input devices such as mouse and keyboard can also create hardware interrupts. Interrupt management and routing devices help to send the hardware interrupts directly to the CPU.

Difference Between Hardware and Software Interrupt

There are two types of hardware interrupts.

Maskable Interrupts – These interrupts can be delayed when the CPU receives higher priority interrupts.

Non-Maskable Interrupt – It is not possible to delay these interrupts. The CPU should consider them immediately.

Each hardware interrupt has a reference number called interrupt number. Each number corresponds to the hardware that generated the interrupt. Therefore, the CPU can easily recognize the device that caused the interrupt. Usually, hardware interrupts are asynchronized events.

What is Software Interrupt

An executing program generates software interrupts. It can communicate with the kernel to invoke system calls. For example, assume that a program requires a valid number for a variable, but it gets a null value. Then, this situation can cause a software interrupt. Assume that the program has an infinite loop. Then, this can cause a memory leak and cause the program to go to an unresponsive state. Furthermore, assume that it is necessary to divide a number by zero. It can cause an exception, and it is a software interrupt. Usually, it is possible to solve software interrupts.

Whenever an interrupt occurs (either hardware or software),  the CPU stops running the currently executing programs and activities.  Then the corresponding interrupt handler is executed. Interrupt handler is also called the interrupt service routine. It is a block of code associated with a specific interrupt condition. After handling the interrupt, the usual programs are executed again.

Difference Between Hardware and Software Interrupt

Definition

A hardware interrupt is an interrupt generated from an external device while the software interrupt is a type of interrupt caused by an instruction in the program. Thus, this is the main difference between hardware and software interrupt. 

Generation

External devices generate hardware interrupts while executing instructions generate software interrupts.

Type

Another difference between hardware and software interrupt is that hardware interrupts are asynchronized events while software interrupts are synchronized events.

Effect on Program Counter

Also, hardware interrupts do not increment the program counter but, software interrupts increase the program counter.

Priority

Priority is another difference between hardware and software interrupt. Software interrupts get a higher priority than hardware interrupts.

Conclusion

An interrupt is a reminder to the CPU to hold on the current tasks and to execute some other task. There are two types of interrupts as hardware and software interrupt. The main difference between hardware and software interrupt is that an external device generates the hardware interrupt while an executing program generates a software interrupt.

Reference:

1. A Brief History of Cryptography – Red Hat Customer Portal, Available here.
2. “Interrupt.” P2P (Peer To Peer) Definition, Available here.
3. “Interrupt Handler.” Wikipedia, Wikimedia Foundation, 14 May 2018, Available here.

Image Courtesy:

1. “PIC Hardware interrupt path” By Jfmantis – Own work (CC BY-SA 3.0) via Commons Wikimedia

About the Author: Lakna

Lakna, a graduate in Molecular Biology and Biochemistry, is a Molecular Biologist and has a broad and keen interest in the discovery of nature related things. She has a keen interest in writing articles regarding science.

Leave a Reply