CS计算机代考程序代写 compiler Communicating with Input and Output Devices Polling

Communicating with Input and Output Devices Polling
What is it?
Interrupts
Drawbacks:  
When is it okay?
Solution:
Programmed Input/Output (PIO) Direct Memory Access (DMA)
 PIO makes a request to read data
 Controller gets data from device
 Controller uses DMA to write data to memory
 Controller interrupts by signaling CPU
 CPU accesses memory

When the CPU is notified by way of an interrupt and then executes the correct Interrupt Service Routine (ISR), would you say this would be a dynamic or static call?
Does the compiler know which interrupt will occur?
How would you suggest the execution of the ISR be implemented?
Using PIO, DMA, and Interrupts

Benefits of using DMA and Interrupts
Code example:
Problem:
Why does this happen, how does diskRead complete before the data is stored in memory?
What is an Event? What is an Event Handler? How can they be used to address asynchronous behavior in a program?
Steps to fixing the problem
1.
2.
3. Implement event handler, callback function (i.e.
compute sum)
4. Include event handler as an argument to the function with async behavior (ie. disk read call)
What needs to happen in order to get expected behavior?
Determine where there is asynchronous behavior (i.e. not
sequential)
Separate the blocks of code

When does computeSum run?
What is wrong with the solution above?
Fix
Add the print statement to computeSum
But what if we wanted to do something else other than print? How do we make our solution more general?
What is the problem with this approach?
What do we do now?