Home Technique Interrupt number

Interrupt number



Interrupt concept

Interrupt refers to the CPU temporarily interrupting the running program due to external/internal random events or events pre-arranged by the program when the CPU is running the program normally. Go to a program that serves external/internal events or pre-arranged events. After the service is completed, return to continue executing the temporarily interrupted program.

For example, when the user uses the keyboard, an interrupt signal is sent out every time a key is pressed to notify the CPU that a "keyboard input" event has occurred, and the CPU is required to read the key value of the key, and the CPU temporarily suspends what is at hand The program is transferred to the read program that processes the key value. After the read operation is completed, the CPU returns to the original program to continue running.

It can be seen that the occurrence of an interrupt is due to a reason. The event that caused the interrupt is the interrupt source. There are various interrupt sources, so there are many types of interrupts. The CPU must give different solutions to the requirements of different interrupt sources when processing interrupt events, which requires an interrupt handler (interrupt service routine) to solve it.

From the logic of the program, the essence of interruption is the transfer of the program. Interrupts provide a mechanism for quickly transferring the operating environment of the program. The program segment that is serviced by the CPU is called the interrupt processing (service) program, and the program that is temporarily interrupted is called the main program (or calling program). The transfer of the program is initiated by the internal event or external event of the microprocessor, and an interrupt process includes two transfers, first the main program transfers to the interrupt processing (service) program, and then to the main program after the interrupt processing (service) program is processed. Transfer. The transfer switching mechanism of the program caused by the interrupt source is used to quickly change the running path of the program, which is very effective for real-time processing of some unexpected events.

Obtaining the Interrupt Number

The interrupt number is the code assigned to each interrupt source by the system for identification and processing. The interrupt number plays a very important role in the interrupt processing process. In the interrupt system that adopts the vector interrupt mode, the CPU must use it to find the entry address of the interrupt service routine and realize the transfer of the program. In order to find the entry address of the interrupt service routine in the interrupt vector table, a pointer can be obtained from the interrupt number (n)×4, which points to the interrupt vector (that is, the entry address of the interrupt service routine) is stored in the interrupt vector table, and this address is taken from it (CS: IP), load the code segment register CS and the instruction pointer register IP, and then transfer to the interrupt service routine.

The method for the CPU to obtain the interrupt number of different types of interrupt sources in the system is different. The interrupt number of the maskable interrupt is obtained from the interrupt controller during the interrupt response cycle. The interrupt number (nil) of the soft interrupt INT nH is directly given by the interrupt instruction. The interrupt number of the non-maskable interrupt NMI and some special interrupts inside the CPU is preset by the system, such as the interrupt number of the NMI is 02H, the interrupt number of the illegal divisor is 0H, and so on.

Use of interrupt number

There are many devices that need to be connected to the computer, such as sound cards, printers, modems, etc. These devices can exchange data with the CPU through interrupt requests. When a device needs the CPU to process its data, it can send an interrupt request signal to the CPU to make the CPU suspend the work being performed, and then process the operation request of the device, and then return to the original work after the processing is completed. When a device sends an interrupt request to the CPU, it tells the CPU which peripheral device needs service through the IRQ value, so each device occupies an IRQ value.

In each computer system, an interrupt controller 8259 or 8259A chip (now this chip is mostly integrated into other chips) controls the interrupt control of each hardware in the system. There are 16 groups of IRQs. Excluding the group of IRQs used as bridges, there are actually only 15 groups of IRQs that can be called by the hardware, and these IRQs have their own default configuration.

When using IRQ values, you need to grasp a principle, that is, an IRQ value can only be used by one device, for example: Usually the mouse uses IRQ4 (COMl), at this time IRQ4 can no longer be used by other hardware devices Up. Different operating system versions have different IRQ settings, so when installing new hardware, the system often cannot automatically detect the correct IRQ to assign to the called hardware, which will cause this hardware device or the original The old hardware is not working properly. In fact, this is because the system automatically assigns the IRQ of the hardware to other hardware that is the same as this IRQ, so that conflicts occur and the hardware cannot work normally. Generally, if you encounter this situation, you can solve it by manually adjusting the IRQ configuration of the new and old hardware.

This article is from the network, does not represent the position of this station. Please indicate the origin of reprint
TOP