Friday 3 December 2010

Electronics for Dogs 6 - Our final idiot

So let's have a recap of our idiot. What can he do?
Well he has a whiteboard with boxes A to H on them.
He has a set of pigeon holes each with 8 switches and lights on them. Normally a switch will turn on the corresponding light, (but not always). Trust me when I say that it turns out to be very cheap to make these pigeon holes. Having billions of "holes" with 8 switches and lights in each hole is not a problem. Because of this we'll give each hole a number, or better yet an address.
He also has a set of instructions that we have given him. However these instructions have to be very simple. Let's have another look at these instructions. How simple can we make them? Let's take it to the limit:

Add the number in box A to the number in box B place the result in box C. If anything odd happens record the oddities with numbers in box D
Copy the value from box x to box y replacing the value in there with the new one (substitute any box designation in here)
Take a value from the pigeon hole number listed in Box D and put that value in Box A
Take the value from Box A and put it in the pigeon hole number listed in Box D
Set box A to value specified.
Test box A if the bit number as specified in Box B is a 1 then do not do the next instruction.
Stop following this instruction stream and start using a different one
And, XOR and NOT instructions. (more on these later)

And there you have it, less than a dozen instructions and capable of solving any problem you can throw at a computer.
Don't believe me? Everything I've discussed so far can be solved with those instructions. now a nice processor will make life easier for you by having more complex instructions, but let's get the basics done first.

One thing to say is with just a dozen instructions then why not have the instructions as a set of numbers? Rather than say "add this to this" then "move this to this" just say 12, 4.
When the instructions are just numbers then then the instructions can be placed into the pidgeon holes too. When our idiot turns up for work in the morning he doesn't have to think. He just looks at address 0 in the pigeon holes and sees the number 5 which tells him that he needs to start by writing 5 into box A then he looks at address 1 and sees he needs to...

Hang on though, how do you work out what numbers to put in there? That's the programming we've discussed but let me give you a final recap before we start getting into the electronics:

User Interface designer says:
We need a box that says Publish Post in it

Programmer Thinks:
First I need to draw a box, then set it's colour, then put the text publish post in it

Programmer writes - in a language I just made up, but not a million miles off:
draw_box(top_left_coordinate, top_right_coordinate, bottom_left_coordinate, bottom_right_coordinate)
Set_colour(orange)
Insert_text("Publish Post")

The Compiler (A piece of software, another program) looks at draw_box and finds the code associated with that. That code includes such things as:
create_triangle(top_left_coordinate, top_right_coordinate, bottom_left_coordinate)
create_triangle(top_right_coordinate, bottom_left_coordinate, bottom_right_coordinate)
so it then looks up create_triangle which includes code such as
vertex_x = coordinate_x + (offset*depth)

Which it translates into:
set A = offset
set B = depth
jump to multiply function
set A = coordinate_x
set B = C
add A to B and place in C
set address vertex_x to C

Which then gets passed to the assembler which can then rattle off a stream of numbers corresponding to the above instructions. e.g. set A to offset is saying set A to the value at memory address (wherever we chose to put offset in memory). so it's just a lookup that it has to do.

Now at this point I'm going to leave computers because I'm not sure more detail is necessary. If you want more detail on any of the above shout and I can always write more. However I'm not currently interested in detailing how for example the 3D rendering engine works no matter how interesting you may find that or otherwise, I just want the concepts to be clear as to what sort of processes you go through to get from a publish post button on a web form to a sequence of numbers in memory.

So next we move onto some electronics. To the point where you might be able to build one of these processors. Might...

No comments: