Program to fill a glass with water from a tap:
Now it may seem childish at first glance, but it is exactly what you do every time you cross a busy street, that has a traffic light. It is also exactly how you would tell a microprocessor to cross the street, if one could. This is what I mean through a sequence or series of very simple steps. Taken like a whole, the steps lead you across a busy intersection, which, if a computer did it, would appear very intelligent. People are intelligent. A programmer that programmed these steps into a microprocessor would impart that intelligence to the microprocessor. Though, the microprocessor would not in this case, know what to do while it got to the other side, since we didn't tell it. A person, alternatively, could decide what to do next, at a moments notice, without any clear programming. In the case of a person, although, there has been some programming; this is called past experiences.
Another program may be to fill a glass with water from a tap.
Step 1
Turn on the water.
Step 2
Put the glass under the tap.
Step 3
Look at the glass.
Step 4
Is it full?
Step 5
If no, goto step 3. (Otherwise, continue to step 6).
Step 6
Take away the glass from under the tap.
Step 7
Turn off the water.
It is a simpler program, with fewer steps, but it solves out a problem, to fill a glass with water. In a microprocessor, the problems are different but the logical steps to solve the problem are similar, that is, a series of extremely simple steps, leading to the solution of a larger problem. Also notice that as the steps are numbered, 1 through 7 that is the order wherein they're executed. In this case, The Program Counter is you, reading each of line, beginning with 1 and ending with 7, doing what each one says. In a microprocessor, the Program Counter automatically advances to the next step, after doing what the present step says, unless a branch, or jump, is encountered. A branch is an instruction that instruct the Program Counter to go to a particular step, other than the next in the sequence. The branch in this instance is step 5. Not only is this a branch, but it is a conditional branch. In other term, based on whether the glass is full or not, the branch is taken, or not. A microprocessor has both branch and conditional branch instructions. Without this capacity to reuse instructions, in sort of looping action, a solution would take several more steps, if it would be possible at all. The point is to illustrate how a simple set of instructions can solve a bigger problem. Taken like a whole, the solution could appear to be more complex than any of the separate steps it took to solve it.
The most complicated problem to be solved in programming a microprocessor is to describe the problem you are trying to solve. Sounds ridiculous but I assure you, it is not. This is the Logical Thought procedure. It is having a good understanding of the problem you are trying to solve out.