ELET2100 - Microprocessors I

Lesson 1: Basics

The majority of  people think that computers are some kind of complicated device that is impossible to learn and infinitely intelligent, able to think better than a person. The truth is much less glamorous.


A computer can only do what the programmer has told it to do, in the form of a program. A program is just a sequence of very simple commands that lead the computer to solve some problem. Once the program is written and debugged (you hardly ever get it right the first time), the computer can execute the instructions very fast, and always do it the same, every time, without a mistake.

And herein lies the power of a computer. Even though the program consists of very simple instructions, the overall result can be very impressive, due mostly to the speed at which the computer can process the instructions. Even though each step in the program is very simple, the sequence of instructions, executing at millions of steps per second, can appear to be very complicated, when taken as a whole. The trick is not to think of it as a whole, but as a series of very simple steps, or commands.

The microprocessor itself is usually a single integrated circuit (IC). Most microprocessors, or very small computers, (here after referred to simply as micro's) have much the same commands or instructions that they can perform. They vary mostly in the names used to describe each command. In a typical micro, there are commands to move data around, do simple math (add, subtract, multiply, and divide), bring data into the micro from the outside world, and send data out of the micro to the outside world. Sounds too simple....right?

A typical micro has three basic parts inside. They are the Program Counter (PC), Memory, and Input / Output (I/O). The Program Counter keeps track of which command is to be executed. The Memory contains the commands to be executed. The Input / Output handles the transfer of data to and from the outside world (outside the micro's physical package). The micro we'll be using is housed inside a 40 pin package, or chip or IC. There are many other actual parts inside our micro however, we will learn about each and every single one, one step at a time.

A Simple Program

As stated before, a program is a sequence or series of very simple commands or instructions. A real world example program might be the problem of crossing a busy street.

Step 1: Walk up to the traffic lights and stop.

Step 2: Look at the traffic light.

Step 3: Is your light green?

Step 4: If the light is red, goto step 2. (otherwise continue to step 5)

Step 5: Look to the left.

Step 6: Are there cars still passing by?

Step 7: If yes, goto step 5. (otherwise continue to step 8).

Step 8: Look to the right.

Step 9: Are there cars still passing by? (there shouldn't be any by now, but, you never know!)

Step 10: If yes, goto step 8. (otherwise continue to step 11)

Step 11: Proceed across the street, carefully!!

Now this may seem childish at first glance, but this is exactly what you do every time you cross a busy street, that has a traffic light (at least, I hope you do). This is also exactly how you would tell a micro to cross the street, if one could. This is what I mean by a sequence or series of very simple steps. Taken as a whole, the steps lead you across a busy intersection, which, if a computer did it, would seem very intelligent. It is intelligence, people are intelligent. A programmer that programmed these steps into a micro, would impart that intelligence to the micro.

The micro would not, however, in this case, know what to do when it got to the other side, since we didn't tell it. A person, on the other hand, could decide what to do next, at a moments notice, without any apparent programming. In the case of a person, though, there has been some programming, it's called past experiences.

Another program might 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: Remove the glass from under the tap

Step 7: Turn off the water.

This is a simpler program, with fewer steps, but it solves a problem, to fill a glass with water. In a micro, the problems are different  but the logical steps to solve the problem are similar, that is, a series of very simple steps, leading to the solution of a larger problem.

Also notice that since the steps are numbered, 1 through 7, that is the order in which they're executed. The Program Counter, in this case, is you, reading each line, starting with 1 and ending with 7, doing what each one says. In a micro, the Program Counter automatically advances to the next step, after doing what the current step says, unless a branch, or jump, is encountered. A branch is an instruction that directs the Program Counter to go to a specific step, other than the next in the sequence. The branch in this example is step 5. Not only is this a branch, but it is a conditional branch. In other words, based on whether the glass is full or not, the branch is taken, or not. A micro has both branch and conditional branch instructions. Without this ability to reuse instructions, in a sort of looping action, a solution would take many more steps, if it would be possible at all.

The point of this lesson is to show how a simple set of instructions can solve a bigger problem. Taken as a whole, the solution could appear to be more complicated than any of the separate steps it took to solve it.

The most difficult problem to be solved in programming a micro is to define the problem you are trying to solve. Sounds silly but I assure you, it's not. This is the Logical Thought Process I mentioned earlier. It is having a good understanding of the problem you're trying to solve. You must understand the information I'm presenting in order pass the course. Trying to remember everything does not work at university.

 On to lesson 2.

Table of Contents