Implementation of event listener
Posted: Sun Jul 08, 2018 11:00 pm
Assembly:
Consider the Intel 8080. To handle an interrupt (for example from the keyboard), you simply have the keyboard pull the 'INT' pin high and place a 'vector' on the databus. The vector points to the location of the interrupt service routine (ISR) in the assembly program code. See this StackOverflow answer for more details.
High level language:
Consider the concept of attaching event listeners. For example consider Javascript's keydown event listener. An example:
When a key is pressed down while the 'demo' element is in focus, myFunction gets called.
Relationship:
How does the concept of attaching event listeners relate to the concept of having ISRs in assembly?
I assume that the function that directly responds to a keyboard interrupt is 1) part of the OS kernel and 2) written in C. (Are these assumptions correct?)
How does a user program tell this OS interrupt handler to alert it upon interrupt? Does the OS function keep a variable size list of functions to callback when it handles an interrupt? Does then addEventListener append the user callback function to the OS function's list?
Note: I chose the Intel 8080 as an example specifically because in contrast to modern CPUs, it does not have fancy capabilities to aid with OS related functionality.
Consider the Intel 8080. To handle an interrupt (for example from the keyboard), you simply have the keyboard pull the 'INT' pin high and place a 'vector' on the databus. The vector points to the location of the interrupt service routine (ISR) in the assembly program code. See this StackOverflow answer for more details.
High level language:
Consider the concept of attaching event listeners. For example consider Javascript's keydown event listener. An example:
Code: Select all
document.getElementById("demo").addEventListener("keydown", myFunction);
function myFunction() {
document.getElementById("demo").style.backgroundColor = "red";
}
Relationship:
How does the concept of attaching event listeners relate to the concept of having ISRs in assembly?
I assume that the function that directly responds to a keyboard interrupt is 1) part of the OS kernel and 2) written in C. (Are these assumptions correct?)
How does a user program tell this OS interrupt handler to alert it upon interrupt? Does the OS function keep a variable size list of functions to callback when it handles an interrupt? Does then addEventListener append the user callback function to the OS function's list?
Note: I chose the Intel 8080 as an example specifically because in contrast to modern CPUs, it does not have fancy capabilities to aid with OS related functionality.