I understand that computers are basically a complex system of electrical signatures that can calculate based on logic boards, and some sort of gate mechanism, but how do computers process something like if the number produced by the keyboard is less than 10, or if a mouse is clicked two times in a certain amount of time it equals a double click?
Not totally sure where you are going with this, and it depends on the hardware The way it all started was.
There's special register in the CPU called Flags Less than is done by a Subtraction. Subtraction is done by addition with two's complement representation. In two's complement negative numbers (bearing in mind overflow) the most significant bit is always 1
So a less than test is Just a - b. The most significant bit of the result is copied to the N bit of the flags register and then that is tested.
There's usually a zero bit to test if A = B and an Overflow bit. A few others as well Carry for istance.
Overflow would be say your number is a signed byte that gives you -128 to + 127 (256 different numbers). so -128 - 1 won't fit and the overflow bit gets set.
There's a load more to this in modern processors, but the basics are still true.
This sort of stuff is a lot easier to pick up in far more basic CPUs than we use now. I learnt it on the Z80 back in 76...
The mouse click one Is store the "time" of the last click. Then on next click subtract the above and then compare it with the interval you stored for how fast you had to click for it to be a double click.
|show 4 more comments|
The CPU is composed of a set of registers. Some are general purpose registers (can be used for computation) and some have dedicated uses (like the instruction pointer which contains the address of the next instruction to fetch). There's a status register (usually) which has several bits such as "overflow." Certain errors are captured by status register flags but its up to the machine code generated or produced from the language you are executing to read the status register and initiate exceptional processing.
Interactive input events are usually handled through interrupts. There's usually an set of interrupt lines into the CPU and when there's a signal on one of those lines that causes the CPU to jump to a new block of code that's called an interrupt handler. Without talking about a particular O/S, the interrupt handler is written as part of the operating system and isn't part of the CPU, although the CPU calls the address provided by the O/S as the interrupt handler. For example, a prototypical O/S, moving the mouse could cause an interrupt, which invokes a serial interrupt handler, which reads the value from the serial port, which then triggers the GUI to redraw, which reads the mouse position and draws the mouse arrow in the right place.
Still other IO is handled through a combination of IO ports and registers and the values are polled periodically for changes.