Monday, January 19, 2009

How a Computer Works


Electricity + Transistors + 1's & 0's + Compiler = How a computer Works.


Electricity

It all starts with electricity. We have metals -- which are conductive, and woods/ceramics -- which are non-conductive (or insulators). In the late 1940s, scientists figured out how to create semi-conductors which are needed to make a "transistor". Semi-conductors are crystals (non-conductive) grown with impurities such as phosphorus (conductive). By forcing crystals of germanium or silicon to grow with impurities such as boron or phosphorus, the crystals gain entirely different electrical conductive properties. By sandwiching this material between two conductive plates (the emitter and the collector), a transistor is made.

Transistors

The transistor is built to pass electrical current through it and maintain a state. A transistor object allows for current to enter on one side and travel to a "fork in the road" so to speak. If the current is high enough to travel up (> 5 Volts) the collector gate is opened and it is interpreted as ON. Otherwise, if it is less than 5 Volts, it does not open the collector gate and the transistor is interpreted as OFF. If it's ON, then we scientists define that as a "1" bit. If it's OFF, that's a "0" bit.

1's & 0's

Representing Numbers with 1's & 0's:
In order for the computer to communicate to us, it has to be able to represent things. The most basic thing it needs to represent is our math system of digits. Otherwise it can't distinguish between a "3" and a "43". Up above, we mentioned the "1" bit and the "0" bit. Those are the only possible states of a single transistor. It can only either be ON or OFF, a 1 or a 0. Therefore, each transistor can either represent the digit 0 or the digit 1. That's pretty limiting. How do we represent the number "5" if we only have a 0 and 1 to work with?

The answer is, we combine this transistor (which can only have 0 or 1) with another transistor (which can also have 0 or 1). By combining these, we can now represent 4 total combinations of values: 0-0, 0-1, 1-0, 1-1. Think of the first combination as the number 0, the second as the number 1, the third as the number 2, and the fourth as the number 3. Thus, with two transistors you can represent up to the number 3. Ok, that helped a little. How do we represent larger numbers?

The answer again is, we add more transistors together (side by side) and then you can represent more combinations. If you think about it now, you can see that we can represent any number out there by combining these transistors. It might take a lot of them, but that's no problem for our latest technology. We can have millions of them in an inch of space.

The Language Part:
Ok, we've discussed how numbers are represented. To represent letters and text on a screen, a computer program needs to interpret numbers (each stored by transistor states described above) as a letter. For example, the number "83", stored by 7 transistors as the combination "1010011", is interpreted as the letter "S".

Compiler

Assembly language is a low-level way of typing commands that a computer understands. It deals with commands like "PUT 0,F0" which tells the computer to switch bit 15 from 1 to a 0. Given that command to turn one bit ON or OFF, you can see that you can turn a bunch of bits to some combination of 1's & 0's. If a series of bits are switched and left alone, this is called "Saving" something into memory. If you saved the number "3", stored by 2 transistors as the combination "11" somewhere, then anytime you want to recall it you can go to the place you saved it and get it.

Compilers allow programmers to write commands that make more sense than "PUT 0,F0". Maybe you typed the following: "In Excel, do the math operation: 5 minus 5". A compiler that understands that higher level language can do the dirty work of figuring out the equivalent low-level series of commands in assembly language (i.e. the numerous lines like "PUT 0,F0"). The coder doesn't have to know about memory locations in the computer he/she is trying to talk to because the compiler turns it into the machine's assembly language. Coders are lazy. If something needs to be repeated they write a program that will do it automatically next time. Some coders wrote the compilers we use so we don't have to translate English to computer talk each time. It does it for us. Remember, once it's in assembly language, the assembly language is interpretted by the computer processor itself, and the transistor is switched. A high-level computer language, like Java, allows coders to write code like "In Excel, do the math operation: 5 minus 5". This in turn is compiled. The compiler puts it into Assembly Language. And the computer processor interprets the Assembly Language and does the bit (1 or 0) shifting.


Summary:

You know it all. The only mind-boggling part is that this is done a super-grand scale. But when trying to understand computers always remember to see the simplest, most basic example before trying to understand it all. For instance, how does the monitor display what you type? Don't think in terms of "pictures" displayed or "words." But instead imagine that your monitor were blown up the size of a house and you could see a single dot/spec in the letter "t" (say the top most dot). Call that a "pixel". And imagine if in that pixel was a bulb with 8 bulbs inside of it. Just like your car brakelights and turn signal, these different-colored bulbs can display the pixel in one of 8 colors. If you can turn just 1 pixel ON and OFF (controlled by a transistor), imagine the possibilities with millions of them controlled by a computer. All you have to do is save off somewhere how to turn one ON. Then save off somewhere how to turn on all the pixels required for "t". Then, if you want to print "t", it goes and calls it. The effect trickles down and it happens. It's not magic. It's some simple principles applied on a grander (yet micro) scale.

No comments:

Post a Comment