How does the computer know what to do
How does the computer know what to do
A computer doesn't actually "know" how to do anything. A computer will do exactly what it is told to do, whether it is good, bad, right or wrong. A computer never looks for the solution to a problem, it merely spits out the output of the instructions it was given.
That said, a computer is turned on. The bios chip activates and has instructions hard-wired into it to know the type of motherboard it has and the locations of all the motherboard chips and slots. The slots run their diagnostic tests and upon a successful test, the bios instructs the hard drive to give the processor further information and instructions to run.
The hard drive usually contains the operating system like Windows or MacOS. The processor now has full control of the system and activates all the peripheral devices and cards that were not activated by the bios, as long as the instructions for those peripherals or cards have been stored on the hard drive. Then it performs diagnostics on those peripherals, and upon success or failure will store that information in a system configuration file which keeps track of the status of these devices for other programs to reference.
For example, if you use PalTalk and Internet Explorer, both programs will want access to a sound output device. Without the system configuration file, each program would independantly have to have instructions on how to turn the sound card on, adjust the volume, and interperet the information into sound through that card. So instead of writing all that code, all the programmer has to do is give the OS a small instruction so the OS can do the rest. It's like a waitress giving an order to the cook. The cook knows how to make a cheeseburger because he read the instructions. All the waitress has to do is say "cheeseburger" and the cook does it automatically. Without the system configuration file, the waitress would have to tell the cook step by step how to make the cheeseburger.
Password protection and encryption are where people get into a lot of trouble if they don't understand this basic principal that computers are STUPID. Computers are like incredibly fast, strong, efficient MORONS who will do absolutely anything that anyone anyone ANYONE tells them to do. Password protection, encryption and firewalls don't give the computer a sense of morality or loyalty. These protections are just another set of instructions. If you type in the incorrect password, a computer doesn't tell you "No," it is saying yes. It is actually giving you the output you requested. Your input was "squirrell34." The computer takes your input, sees that "squirrell34" is different from "slick20" and cheerfully gives you your requested output, "Access Denied." Even though you paid for the machine and have a God-given right to the output that you *want* the computer will always give you the output that you *requested* by way of your input filtered through the instructions.
Now here comes Darth Vader. He stumbles upon a piece of paper that says "squirrell34". Darth Vader breaks into your home and types it in. The computer sees that the input "squirrell34" is equal to "squirrell34" so it takes a look at Darth Vader, doesn't believe him and asks for some ID, right? Nope, it gives the Imperial Lord your recipe for chocolate asparagus without a second thought.
Anyway, that's the basic answer -- computers don't know what to do. Computers are just big collections of tiny lightswitches that turn on other tiny lightswitches when we arrange them properly.
I'm just kidding. It's actually magic.
The computer checks for actions and/or conditions specified in its programming/code and then reacts according to what is written in its programming. An example:
Loop Do (
This is where the computer goes back to when specified to)
When
Microsoft Word is open (
condition 1)
When able to type (
another condition)
When a keyboard button is pressed (
a third, more broad condition )
Save the pressed button in memory as a variable named "blabla"
Draw the pressed button (known as variable "blabla")(
Reaction/Action)
Loop (
Start over from Loop Do)