Differences between interrupts and traps

在学习操作系统的过程中我遇到了 中断(interrupt) 和 陷阱(trap) 有些许疑惑它们有什么区别搜索一番找到一篇不错的解释

出处:http://vspages.com/interrupt-vs-trap-6620/


Interrupt vs. Trap

Difference Between Interrupt and Trap

There are certain events during the use of a computer which cause the CPU to come to a halt temporarily. These events are called interrupts. They are due to faults in hardware or software of the computer. If the halts are caused by the hardware, it will be called interrupt. On the other hand if the halt is caused by software, it will be called Trap or exception. In exception, the software generates automatic interruption.  Trap is an interruption caused by the programmer. In case of interrupt the control is given to the special subordinate termed as Interrupt Service Routine or ISR.

Interrupt

The word ‘interrupt’ is generally associated with hardware. The interrupt is caused by some external hardware events. Interrupts come from different sources like peripheral devices including mouse and keyboard, serial ports and parallel ports etc, disk drives, expansion cards like audio and video cards. Interrupt is not caused by any program related event. For example a key is pressed on the keyboard by the user, the interrupt sends the information that certain device needs attention. At an interrupt, the CPU will stop working its normal function. It will return to its normal function after correcting the interrupt. When CPU starts the ISR at the time of hardware interrupts, other interrupts are disabled. Interrupt flags have to be cleared if the user wants other interrupts to occur at the time of the running of ISR.

Trap

A Trap is a transfer of control initiated by the programmer. Trap and Exception are used interchangeably. Exception is an automatically occurring software interrupt. Some users suppose that a trap is a special subroutine call. That is why they are categorized as software invoked interrupts. The control in case of trap is transferred to the subordinate associated with the trap as a trap is always unconditional. The instruction invoking the routine for handling the trap is identified easily as an interruption is specified by an explicit instruction.

Difference between Interrupt and Trap

The major difference between the two is that interrupts are caused by hardware while traps are interrupts caused by software. Other hardware interrupts get disabled in hardware interrupt. But it is not so in case of traps. A user has to clear the interrupt flag if he wants to disallow hardware interrupts till a trap is served. The interrupt flag affects hardware. Clearing the flag does not prevent traps. The interrupts should restore the previous state of the CPU.

出处:http://vspages.com/interrupt-vs-trap-6620/

如有侵权,立刻删除。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值