ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Computer Organization and Assembly Language
    COMP3137
    Progress0 / 73 topics
    Topics
    1. Introduction to Computer Organization2. Assembly Language3. Comparison of Low-Level and High-Level Languages4. Register Types (16-bit): General Purpose and Special Purpose Registers5. Introduction and Usage of RAM6. Processor7. Registers8. System Bus9. Instruction Execution Cycle10. Assembly and Machine Language11. Assembler12. Linker and Link Libraries13. Programmer's View of a Computer System14. RISC and CISC Architecture15. Physical Address Calculation16. Basic Memory Organization17. CPU Organization18. Top Level View of Computer Function and Interconnection19. Assembler Instruction Cycle20. Execute Cycle21. Interrupts22. Interrupt Cycle23. Memory Connection24. Input/Output Connection25. CPU Connection26. MASM27. MIPS28. Defining Data in MASM Assembler29. Elements of Assembly Language30. Integer Constants31. Integer Expressions32. Real Number Constants33. Character Constants34. String Constants35. Reserved Words36. Identifiers37. Directives38. Instructions39. The NOP (No Operation) Instruction40. Adding and Subtracting Integer41. INC and DEC Instructions42. NEG Instruction43. How to Move Integer Number in Register44. Adding and Subtracting Numbers in Registers45. Declaration and Initialization of Variables46. Moving Data from Variable to Register47. Data Definition Statement48. BYTE and SBYTE Data49. WORD and SWORD Data50. Defining DWORD and SDWORD Data51. Knowledge about Different Data Types52. Operations, Array & Loops53. Division and Multiplication in Assembly54. Jumps Based on Specific Flags55. Jumps Based on Equality56. Simple Jump Statements57. Jumps Based on Specific Condition58. Code Examples59. Practice on MASM60. Procedures61. File Operations Procedures62. Labels in Procedures63. Stack64. Runtime Stack65. Conditional Control Flow Directives66. Compound Expressions67. Data Representation & Conversion68. Architecture69. Data Path70. Control Unit71. Critical Path72. General Principles of Pipelining73. Pipelined Y86 Implementations
    COMP3137›Interrupts
    Computer Organization and Assembly LanguageTopic 21 of 73

    Interrupts

    8 minread
    1,374words
    Intermediatelevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time8 min
      Word count1,374
      Code examples0
      DifficultyIntermediate