> For the complete documentation index, see [llms.txt](https://nec-license.gitbook.io/books/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nec-license.gitbook.io/books/2.-digital-logic-and-microprocessor/2.6-interrupt-operations.md).

# 2.6 Interrupt Operations

### 1. **Interrupts**

**Interrupts** are signals that alert the microprocessor to stop its current operations and attend to more urgent tasks which is typically triggered by hardware devices or software.

There are basically two types of interrupts:

* **Hardware Interrupts**: Generated by external devices, such as input from a keyboard, mouse, or sensor.
* **Software Interrupts**: Triggered by software instructions (e.g., a system call or software exception).

### **2. Interrupt Service Routines (ISRs)**

**Interrupt Service Routine (ISR)** is a special function or set of instructions executed when a specific interrupt occurs. Each interrupt is assigned an ISR, which is responsible for handling the interrupt and then returning control back to the main program.

The different steps involved in the ISRs:

1. **Interrupt Request (IRQ)**: An interrupt is raised by the hardware or software.
2. **Interrupt Acknowledgment**: The microprocessor acknowledges the interrupt.
3. **Execution of ISR**: The ISR is executed to handle the interrupt.
4. **Return to Normal Operation**: Once the interrupt is processed, the CPU resumes the previously interrupted task.

### **3. Interrupt Processing**

The **interrupt processing cycle** involves the following steps:

1. **Interrupt Occurrence**: An interrupt is triggered.
2. **Interrupt Detection**: The processor detects the interrupt signal.
3. **Interrupt Acknowledgment**: The processor acknowledges the interrupt and saves the current execution state (e.g., registers, program counter) to preserve the ongoing task.
4. **ISR Execution**: The processor jumps to the corresponding ISR address to execute the interrupt-handling code.
5. **Context Restoration**: After the ISR is completed, the processor restores the saved execution state and resumes normal program execution.

### 4. **Types of Interrupts:**

There are usually two types of interrupts:

* **Maskable Interrupts**: Can be disabled (masked) by the CPU to avoid interruption during critical processes.
* **Non-Maskable Interrupts (NMI)**: Cannot be disabled and have higher priority, typically used for critical events like hardware failure.

### 5. **Interrupt Priority**

When multiple interrupts occur simultaneously, the processor must determine which one to address first. This is often done through an **interrupt priority scheme**.

There are usually two types of interrupts priorities:

* **Fixed Priority**: Each interrupt source has a fixed priority level, and the processor serves the highest-priority interrupt.
* **Dynamic Priority**: The priority may be changed depending on the circumstances or the type of interrupt.

### **6. Interrupt Vector Table**

The **interrupt vector table** is a table in memory that stores the addresses of ISRs for various interrupt sources. When an interrupt occurs, the processor looks up the ISR address in the interrupt vector table to know where to jump for processing.

***

### Conclusion

Interrupts are signals that temporarily pause the CPU's tasks to handle urgent events, triggered by hardware (e.g., keyboard) or software (e.g., exceptions). An ISR manages each interrupt, ensuring tasks resume after processing. Interrupts can be maskable (disable-able) or non-maskable (critical, high-priority). The CPU uses an interrupt vector table to locate ISR addresses.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://nec-license.gitbook.io/books/2.-digital-logic-and-microprocessor/2.6-interrupt-operations.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
