I/O & Interrupts — Polling, IRQs & DMA
Peripherals are slow compared to a CPU: a disk read can take milliseconds, which is millions of CPU
Peripherals are slow compared to a CPU: a disk read can take milliseconds, which is millions of CPU
There are exactly three ways to get a byte out of a peripheral register and into your program's memory. The CPU can ask repeatedly until the answer is yes. The peripheral can raise a line that makes the CPU stop what it was doing. Or a second bus master can do the load and the store on the CPU's behalf and tell it afterwards. Every driver you will ever write picks one of these, and the choice is made badly far more often than it is made wrong — badly, meaning by reflex rather than from a budget.