ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3137Interrupts
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3137

    Computer Organization and Assembly Language

    Progress0 / 73 done
    Topics73
    1Introduction to Computer Organization2Assembly Language3Comparison of Low-Level and High-Level Languages
    4General Purpose and Special Purpose Registers5Introduction and Usage of RAM6Processor7Registers8System Bus9Instruction Execution Cycle10Assembly and Machine Language11Assembler12Linker and Link Libraries13Programmer's View of a Computer System14RISC and CISC Architecture15Physical Address Calculation16Basic Memory Organization17CPU Organization18Top Level View of Computer Function and Interconnection19Assembler Instruction Cycle20Execute Cycle21Interrupts22Interrupt Cycle23Memory Connection24Input/Output Connection25CPU Connection26MASM27MIPS28Defining Data in MASM Assembler29Elements of Assembly Language30Integer Constants31Integer Expressions32Real Number Constants33Character Constants34String Constants35Reserved Words36Identifiers37Directives38Instructions39The NOP (No Operation) Instruction40Adding and Subtracting Integer41INC and DEC Instructions42NEG Instruction43How to Move Integer Number in Register44Adding and Subtracting Numbers in Registers45Declaration and Initialization of Variables46Moving Data from Variable to Register47Data Definition Statement48BYTE and SBYTE Data49WORD and SWORD Data50Defining DWORD and SDWORD Data51Knowledge about Different Data Types52Operations, Array & Loops53Division and Multiplication in Assembly54Jumps Based on Specific Flags55Jumps Based on Equality56Simple Jump Statements57Jumps Based on Specific Condition58Code Examples59Practice on MASM60Procedures61File Operations Procedures62Labels in Procedures63Stack64Runtime Stack65Conditional Control Flow Directives66Compound Expressions67Data Representation & Conversion68Architecture69Data Path70Control Unit71Critical Path72General Principles of Pipelining73Pipelined Y86 Implementations
    8 min read
    Topic 21 of 73
    Topic Study Note Illustration
    21

    Interrupts

    An interrupt is a mechanism by which the normal flow of execution in a CPU is temporarily halted to handle a specific event or condition. After handling...

    Interrupts in Computer Systems

    An interrupt is a mechanism by which the normal flow of execution in a CPU is temporarily halted to handle a specific event or condition. After handling the event, the CPU resumes its previous execution. Interrupts are crucial for managing events that require immediate attention, such as hardware malfunctions, user input, or scheduled tasks, without constantly checking for those events (i.e., without polling).

    Why Interrupts Are Important

    Interrupts allow the CPU to respond to high-priority events, like hardware requests or user actions, without needing to continuously monitor or check for them in the main program loop. This enables the system to handle multiple tasks more efficiently, ensuring that important events are not missed.

    Interrupts are used for tasks like:

    • Handling input/output (I/O) devices: For example, when data is available from a keyboard, mouse, or network interface.
    • Multitasking: Operating systems use interrupts to allow the CPU to switch between tasks, giving the illusion of simultaneous processing.
    • Error handling: If a device fails or a program encounters an issue, an interrupt can signal the CPU to handle it.
    • Time-sensitive events: For example, the system clock generates interrupts at regular intervals to maintain time or schedule tasks.

    Types of Interrupts

    Interrupts can be broadly classified into two categories:

    1. Hardware Interrupts
    2. Software Interrupts

    1. Hardware Interrupts

    Hardware interrupts are generated by physical hardware devices or external events that require the CPU's attention. These interrupts are triggered by external hardware components, such as input devices, sensors, or timers.

    • Examples:

      • Timer Interrupt: A timer can interrupt the CPU after a set time period, allowing the operating system to perform tasks like context switching (changing from one process to another) or updating the system clock.
      • Keyboard Interrupt: When a key is pressed, the keyboard controller sends an interrupt signal to the CPU to indicate the key press.
      • I/O Device Interrupt: If an I/O device (such as a printer or disk drive) is ready for data transfer, it sends an interrupt to notify the CPU.
    • Types:

      • Maskable Interrupts: These interrupts can be ignored (masked) by the CPU if necessary. For example, the CPU might decide to mask certain interrupts when performing critical tasks.
      • Non-maskable Interrupts (NMI): These interrupts cannot be ignored by the CPU, as they typically signal critical errors like hardware failures or system crashes.

    2. Software Interrupts

    Software interrupts are triggered by software running on the CPU. These are typically used to request a service from the operating system or to handle specific program conditions. Software interrupts allow programs to request the operating system to perform specific functions without having to directly access hardware resources.

    • Examples:

      • System Call: A program can trigger a software interrupt to request a service from the operating system, like opening a file or allocating memory.
      • Breakpoints/Exceptions: Programs may raise interrupts to handle errors, such as division by zero or invalid memory access.
    • Types:

      • Synchronous Interrupts: These occur as a result of a specific action by the running program, such as a division by zero error or an illegal instruction.
      • Asynchronous Interrupts: These are not related to a specific program instruction and can occur at any time, such as a timer interrupt or an I/O request.

    Interrupt Handling Process

    The process of handling an interrupt is referred to as interrupt handling or interrupt servicing. Here's a step-by-step breakdown of what happens when an interrupt occurs:

    1. Interrupt Occurs:

      • When an interrupt is triggered, the CPU suspends its current task and jumps to a special location in memory, known as the interrupt vector or interrupt service routine (ISR).
    2. Save Context:

      • The CPU saves the current state of execution (context), including the Program Counter (PC) and register values, so it can return to the task later after handling the interrupt. This process is called context saving.
    3. Interrupt Service Routine (ISR):

      • The CPU begins executing the interrupt service routine, a special piece of code designed to handle the interrupt. The ISR performs tasks like reading data from an I/O device, handling an error, or performing other necessary actions related to the interrupt.
    4. Return from Interrupt:

      • Once the ISR is completed, the CPU restores the previous state (context) from the saved registers, and execution resumes from the point where it was interrupted. This is called context restoration.
      • The Program Counter (PC) is restored, and execution continues as if the interrupt had never occurred.

    Interrupt Vector Table

    To know where to go for each interrupt, the CPU uses an interrupt vector table. This table is a list of addresses where the respective interrupt service routines (ISRs) are located.

    • When an interrupt occurs, the interrupt vector is used to find the address of the appropriate ISR.
    • The ISR address is typically pre-defined by the operating system or hardware configuration, ensuring that the correct routine is executed when a particular interrupt occurs.

    Masking and Prioritization of Interrupts

    Since a computer system may have many interrupt sources, it is important to manage how interrupts are handled, especially when multiple interrupts happen simultaneously. There are two key concepts for managing interrupts:

    1. Interrupt Masking:

      • Interrupts can be masked (disabled) or unmasked (enabled) by the CPU. Masking interrupts allows the CPU to ignore specific interrupts when it is performing critical tasks. Masking is often controlled by special interrupt mask registers.
      • For example, during a time-sensitive operation, the CPU may mask lower-priority interrupts to prevent them from interrupting the current task.
    2. Interrupt Prioritization:

      • Since multiple interrupts may occur at the same time, the system often uses a priority scheme to determine which interrupt should be handled first. Interrupts with higher priority are processed before lower-priority ones.
      • This is particularly important in real-time systems where certain interrupts, like timer interrupts, must take precedence over others.

    Some systems use Priority Interrupt Controllers (PICs) or Programmable Interrupt Controllers (PICs) to manage and prioritize interrupt handling.


    Example of Interrupt Handling

    Consider an example of handling a keyboard interrupt:

    1. Interrupt Occurs:

      • The user presses a key on the keyboard. This triggers an interrupt from the keyboard controller.
    2. Interrupt Service Routine (ISR):

      • The CPU suspends its current operation, saves the current state, and jumps to the address of the keyboard ISR.
      • The ISR checks which key was pressed and places the corresponding data into a buffer.
    3. Return from Interrupt:

      • After the keyboard ISR finishes handling the key press, the CPU restores the state of the program it was executing before the interrupt and continues from where it left off.

    Types of Interrupts and Their Uses

    Here are some common types of interrupts and their typical uses:

    1. Timer Interrupts: Used for time-sharing systems to switch between processes, maintain system clocks, or schedule tasks.

    2. I/O Interrupts: Triggered by hardware devices like keyboards, mice, network interfaces, printers, etc. When a device is ready to send or receive data, it generates an interrupt.

    3. Hardware Failure Interrupts: Non-maskable interrupts (NMIs) triggered by critical hardware failures such as memory errors, power failures, or system crashes.

    4. Software Interrupts (System Calls): Generated by software (e.g., programs or operating systems) to request services from the operating system.


    Advantages of Using Interrupts

    • Efficiency: Interrupts allow the CPU to perform other tasks until it needs to respond to an interrupt, instead of wasting time constantly polling devices for data.
    • Responsiveness: Critical events can be handled immediately, improving system responsiveness (e.g., reacting to user input or hardware errors quickly).
    • Multitasking: Interrupts allow the CPU to switch between tasks efficiently, supporting multitasking and process scheduling.
    • Low Overhead: Interrupts reduce the need for constantly checking device status (polling), which saves processing time and reduces system load.

    Conclusion

    Interrupts are a crucial mechanism for managing asynchronous events in a computer system. They allow the CPU to respond to events like I/O requests, hardware errors, and time-sensitive tasks without needing to continuously check for them. Interrupts provide a way to interrupt normal program flow to handle these events, improving efficiency and responsiveness in the system.

    By utilizing interrupt vectors, handling priority and masking of interrupts, and executing interrupt service routines (ISRs), computers can effectively manage multiple tasks and respond to both hardware and software events promptly.

    ← Previous topic 20
    Execute Cycle
    Next topic 22 →
    Interrupt Cycle

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    8mremaining
    1.4kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language