几个概念
Polling (轮询)
定义
轮询设备的状态,确保它们正常工作
特点
-
可以实现简单、可靠的设备管理
-
消耗大量的处理器时间
中断
定义
外部设备通过向处理器发送信号打断正在运行的程序
特点
- 异步的,由外部事件触发
实例
-
移动鼠标
-
使用键盘
-
打印
结果
-
当前指令被打断
-
保护当前指令的状态,八个寄存器被放入栈
-
寄存器
-
LR(Link)被设为0xFFFFFFF9
-
IPSR (Interrupt Program Status Register) 被设为Interrupt Number
-
PC(Program Counter)加载Interrupt vector
比较
-
中断是一种事件驱动的控制方式,当一个事件发生时(例如外部设备发出的信号),处理器会暂停当前执行的程序,转而执行与该事件相关的中断服务程序(ISR)。ISR执行完毕后,处理器会恢复之前的执行状态,继续执行被中断的程序。中断具有实时响应、低处理器占用率等优点,适用于需要快速响应外部事件的应用场景。
-
轮询是一种基于循环的控制方式,程序会周期性地检查某个条件是否满足,然后决定下一步操作。轮询通常在一个无限循环中执行,会占用处理器的大量时间。轮询适用于处理器资源较为充足,但需要周期性检查某个条件的应用场景。
分类 | 中断 | 轮询 |
---|---|---|
背景 | 在需要时调用处理器 | 定期查询 |
机制 | 机制 | 协议 |
Servicing | Interrupt Handler | CPU |
中断处理程序设计
- Let us consider a main process with an interrupt, where the main process is to input 10 random numbers with range [0, 100], and the interrupt is to input {$11^2 , 12^2 , 13^2 , … , 20^2$} once the input number in the main process is out of range.
C++程序(不确定能不能跑)
|
|
汇编程序
中断的情况
- 当除法溢出时,就会中断
程序-输出overflow
|
|