Tuesday, August 24, 2010

Programming Languages / Layers of Abstraction, Part 2

Well, at least someone commented, and it was provocative (to me) enough to merit another post. Though even if it weren't I would probably write another post anyway. Here is the comment:
mpk3 said...
Thank you Matthew. I think that helped me, but I am still wondering what those different conversations in machine, assembly, symbolic, and programming languages mean. Could you translate for us? What would those rows of numbers and letters accomplish on a computer?

First, OH NOOOO!, my name has been revealed, and the initials of the commenter have been revealed as well, I think the world is going to explode.

I guess it didn't. Well, it appears the question is aimed at computing on an even smaller level. This lower level, lower than code, is the actual circuit, which again, not surprisingly is also very similar to human thought. It relies on small silicon circuit gates. At this point there is a huge design compromise, either you can make a chip which can differenciate between 2 voltages, thus the 0 and 1, or the more efficient but less expensive circuits which can differenciate between as many voltages as you would like. But if you take the latter route the problems snowball. You now need a power supply that is even more precise with the current it outputs, and you need to develop a standard amount of voltages that can be detected. If not, person A will make a computer that is totally incompatible with the computer that person B made. So for all parties involved it is easier and cheaper to go with a circuit of a set resistance. If the current reaching the circuit is above the threshold, it moves on (1), if not (0).

To get anything useful done with such a basic component, you're going to need to chain them together. Here's where symbolic logic becomes useful again.

NOT gate:
the most fundamental unit in computing, it is simply a single transistor. It always receives a 1 from the power pulsing through the computer and then takes an input value, if it receives another 1, it outputs 0, if it receives a 0, it outputs a 1. The following circuits are made from multiple NOT gates

OR gate:
takes two inputs (which, consequently are outputs from other circuits), and if at least one is a 1, outputs a 1 (which, consequently is an input for the next circuit), if both are 0, than it outputs a 0

AND gate:
takes two inputs, and if both are 1, then it outputs a 1, otherwise it outputs a 0

XOR gate:
takes two inputs, it 1 is a 1 then it outputs a 1, if both are 0 or both are 1, it outputs a 0

To illustrate what happens at the most basic level, i will use an example out of the book, 'How Computers Work' by Ron White.

The computer adds (which is really the only thing it can do) using combinations of gates called adders. First, a half-adders, which can only add 2 single binary digits. For instance 1 and 1. A half adders combines the output of an AND and an XOR gate. So 1 and 1 are sent to an AND gate, producing a 1. Then 1 and 1 are sent to an XOR gate, producing a 0. Put 1 and 0 together you get 10 binary, which is 2 in decimal. A full adder is simply a more elaborate collection of gates that i cant explain without a drawing. Also, a full adder must be combined with a half adder to add 2 digit binary numbers, thus getting more complex.

save image
This is all meant to illustrate the lowest level of computing, how 10+11, when run through a combination of circuits ends up as 101.

So now up to the higher levels, which are actually quite dissapointing, but it's what mpk3 asked for. Well, a low level is this 0110101010111, and if you translate a higher level command such as 'if (x == 3) System.out.println("Yes");" you would get something like this 10110101011101010001001010101010000001110101011010100101010000000111111111110100010111011010101000110111111011010101011001011010101010101010101101etc. And if you go up even higher you just get more of the same. So really computing from that standpoint comes down to righting a combination of 1s and 0s, called a compiler, which will turn commands such as 'disp' or 'out' into more 1s and 0s, or commands such as clicking a link and scrolling down a webpage into even more 1s and 0s.

But, as i close, how is this similar to human thought. A neuron is simply a collection of cells which takes input from other neurons, if the input from other neurons is strong enough, it gives an output. A neuron is both organic and far more advanced in that it can take many many inputs and produce one outputs, where a circuit is limited to only two inputs.

As always, leave comments and suggestions for future posts.

Further Reading:
How Computers Work, by Ron White

2 comments:

  1. Mr. Anonymous,
    Regarding your anonymity, I will seek to keep as anonymous as possible, Mr. Anonymous. I have a question about website design. What exactly is the process of making a webpage?

    ReplyDelete
  2. Also, Mr. Anonymous, don't forget the post you had thought of when you were talking to me about GPUs and such. Apparently it will be massive.

    ReplyDelete