例外情况与中断
当我寻找异常和中断之间的区别时, 我发现这个问题中断和异常关于SO...
有些答案不适合(至少对于汇编级):
“例外是软件版本的中断” 但是存在软件中断!!
“中断是异步的,但异常是同步的” 是这样吗?
“定期发生中断”
“中断是硬件实现的陷阱,异常是软件实现的” 同上!
我需要找出其中一些答案是否正确,如果有人可以提供更好的答案,我也将不胜感激......
谢谢!
When I was searching for a distinction between Exceptions and Interrupts,
I found this question Interrupts and exceptions on SO...
Some answers there were not suitable (at least for assembly level):
"Exception are software-version of an interrupt" But there exist software interrupts!!
"Interrupts are asynchronous but exceptions are synchronous" Is that right?
"Interrupts occur regularly"
"Interrupts are hardware implemented trap, exceptions are software implemented" Same as above!
I need to find if some of these answers were right , also I would be grateful if anyone could provide a better answer...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
中断通常是一种发出硬件状态变化信号的方法。外设将通过电信号连接到中断控制器,该控制器对每个可能的信号进行优先级排序并分配地址向量。中断控制器将检测到的中断条件转发给CPU,CPU可能会也可能不会“中断”其当前执行状态以处理通知的状态变化(取决于是否启用中断和/或该特定输入是否不可屏蔽)。在某些架构上,除了硬件输入之外,中断条件还可以由软件启动(例如在 x86 上有一个 int 助记符)。
例外情况涉及更大的实施范围。在某些 CPU 架构(例如 68K)中,异常可能类似于中断,但由需要处理的某些 CPU 状态生成。例如,除零、非法指令、I/O总线超时等情况都会产生异常。通过处理这些异常,我们可以执行诸如模拟指令和虚拟扩展指令集等操作。
异常也可能是纯软件概念,例如在 C++ 语言中,可以捕获和处理某些错误条件。
因此,一般来说,您试图确定其有效性的陈述可能是正确的或错误的,具体取决于您应用它们的确切平台。
Interrupts are typically a method of signaling a change in hardware state. Peripherals will be tied by electrical signal to an interrupt controller which prioritizes and assigns address vectors to each possible signal. the interrupt controller forwards a detected interrupt condition to the CPU which may or may not 'interrupt' its present execution state to process the signaled state change (depending on whether interrupts are enabled and/or whether this particular input is non-maskable). Interrupt conditions may, on some architectures, be initiated by software (such as on the x86 there is an int mnemonic) in addition to hardware input.
Exceptions span a greater range of implementation. In some CPU architectures such as 68K, an exception can be similar to an interrupt but is generated by some CPU state that needs to be handled. For example there are conditions such as divide by zero, illegal instruction, I/O bus timeout, etc. that generate exceptions. By handling those exceptions one can do things such as emulate instructions and virtually extend the instruction set.
Exceptions may also be a software-only concept such as in the C++ language where certain error conditions can be trapped and handled.
So in general, the statements you are trying to find the validity of may be true or false depending on the exact platform you are applying them to.
最常用的异常是编程语言中的一种控制流形式,用于处理程序正常逻辑流之外的事件,以避免程序的业务逻辑淹没在错误处理逻辑中。异常的“处理”是特定于上下文的。它更像是一种 GoTo,适用于许多有用的用例。
中断是一种硬件辅助“陷阱”,用于在发生某些事件时触发某些操作,如定时器滴答或程序“调用”INT21。有一个注册的处理程序可以执行预定义的操作。
两者可能是同步或异步的,也可能不是。
An exception as it is used most often is a form of control flow in a programming language to deal with events outside the normal logic flow of the program to avoid that the business logic of a program drowns in the error handling logic. The 'handling' of the exception is context specific. It is more like a kind of GoTo for a number of use-cases where it was useful.
An interrupt is a hardware assisted 'trap' to trigger certain actions when certain events occur, as a timer tick or program "calling" INT21. There is a handler registered which does something predefined.
Both may or may not be synchronous or asynchronous.