Friday, September 28, 2007

Basic Computer Architecture

Let's get started. First, I want to introduce you to the essential functional units of a computer to help you understand how the computer goes about running your code.
Everything you enter into the computer (whether you type it on the keyboard, load it using a disk, scan it, etc.), is read into the memory of the computer. This can be data or program and is commonly called input, entered using any of the several input devices. They are all placed in the memory of the computer as they are loaded. This information could be read into the processor for some kind of ... (you guessed it!) processing. After the processing is done, the resulting information, now called the output is placed right back into memory. From there, the information can be moved to a printer, to disk, on screen or through any other 'output device'. This is all handled by the operating system.

Physically speaking, most of what you do as a programmer is to (a) specify to the operating system (or the runtime of your platform) to create various kinds of locations in the memory of the computer (variables). (b) You'd then ask it to store matching kinds of data in those spaces (assignment). (c) You also specify where you data will come from. (d) And then, you specify instructions (instructions) that the system will use to operate on those data stores. (e) Finally, you provide instructions as to where the computer will direct the output to.

So, when the operating system starts your program, it loads the instructions into memory. Then it creates space, also in memory for the data. Then, it starts executing each instruction one afte the other until they finish or it encounters a halt instruction or an error. In the ordinary sense, the instructions are executed one after the other, in the order they textually appear. However, some of those instructions are jump instructions which tell the computer to jump (or branch) to another location other than the very next line of instruction.

Let's look at a sample pseudo-program and see how the computer will execute it.
Pseudo-program, otherwise known as pseudocode is not written in any programming language. It is written in some kind of tecky human language. It is just meant to specify what is yet to be coded. Often, it is convenient to express a program in pseudocode so that everyone, regardless of their programming language of choice can still understand it.
Sample code (pseudo):
  1. Enter first number as 10
  2. Enter second number as 5
  3. Store third number as firstnumber MINUS second number
  4. PRINTOUT first number - second number = third number.

Expected result will be:

10 - 5 = 5.

What just happened? The programmer specified a set of instructions. These incuded creating a space in memory for storing 3 numbers. One of them is the constant 10, another is the constant 5 and the third is a result number from an operation named MINUS . The last instruction is called PRINTOUT whose duty is to take information from a location in memory and draw it on a human interface, eg: screen or paper.

You will notice that the MINUS instruction will require the processor to do something with two numbers in specified locations in memory and produce a third number which, in this case, gets put into a third location in memory.

Most of the time, this is a summary of what programmers do for a living. As we proceed, you will see that these few lines of 'code' do actually represent nearly every kind of program every written by man to solve any conceivable kind of human problem.

See! You can do it. Stay with me.

No comments:

Post a Comment

Thanks for stopping by. Feel free to leave your mark.