views:

1371

answers:

17

What is the best description of the CPU that can fit in 500 words? Submit and vote up actual attempts. Imagine you're explaining it ...

  • to some non-cs grad students over dinner
  • to the smartest, most interested 12 year old you've ever met
  • to a beginning programmer in a high-level language who knows how to count, add, subtract, and multiply in binary
  • anyone capable of understanding how it works
+2  A: 

http://computer.howstuffworks.com/microprocessor.htm

Might be helpful

GreenRails
+1  A: 

I doubt you can get it down to 500 hundred words, but the Chinese Room metaphor isn't completely off in left field.

Note that we are not interested in the whole AI debate here. Just the description of how you could accomplish complex calculation on the basis of simple instructions for writing stuff on cards and putting them in pigeonholes.

This certainly isn't all inclusive: it just gets at the idea that "a computer does a lot of simple things very fast".


I'd suggest separating the above concept from questions on the lines of

  • how are numbers (integer and float), pointers, text represented in memory
  • how are bits, bytes, etc represented on a wire or bus
  • how are logical and arithmetic operations accomplished in hardware (BTW-- The binary marble adder is a wonderfully geeky (and nearly hypnotic) visualization.)
  • ...

You can probably pare each of these down to a reasonable lengths.

Trying to tackle the whole "How does a CPU work" problem would seem to involve multiple levels and a lot of different problems.

dmckee
Thanks for the suggestions!
Peter Nore
A lot can be accomplished in 500 words. I'm hoping the programming community will be able to explain what makes its heart beat. http://docs.google.com/Doc?id=dgzqsgjz_43c75smjgghttp://docs.google.com/Doc?id=dgzqsgjz_33vk9kqtfmhttp://docs.google.com/Doc?id=dgzqsgjz_32g3wqz26z
Peter Nore
+3  A: 

I don't think there is a description of a CPU succinct enough to fit your initial requirements. Perhaps if you narrowed it down by grade level a bit, since obviously 12th graders can conceptualize a lot better than 7th graders.

Still, I think all of the things they "wonder" do lend themselves to a few short lessons if you have the extra class time to teach them.

I think even an "advanced math" 7th grade can handle a little bit of "5-bit" simple math (addition, subtraction, multiplication). Being able to count to 31 on one hand is a pretty cool trick.

Interrupts are really a rather simple concept, and they are the heart of how the CPU "knows what to execute next." Where the instructions come from (memory) is pretty obvious, but once you understand how the CPU switches between programs and that EVERYTHING (even the OS) is the same type of code, this falls more in to place.

Once you have that down, you could introduce them to MIPS o some other RISC instruction set which has very few operations or even create your own very simple instruction set which demonstrates how just a few operations can do a whole lot. Maybe even practice writing simple assembly using this fake instruction set. To make it easier than real assembly, you can name the instructions more obviously, forget the whole concept of registers (just let them use variable names), etc.

Five hundred words though really isn't going to do it justice, but I think 5 or so class hours while being just a "taste" could actually provide a lot of information, and of course peak some interest to learn more... which is really the whole point anyways.

SoapBox
Thanks for your comment. MIPS was how I was taught about the CPU, that's a great choice for teaching. But I'm definitely not asking for tips on how to teach here though, or even an essay that gives "justice" to the situation. Just the "simplest and best" description.
Peter Nore
"being able to count to 31 on one hand" - yeah, but getting in trouble for the number '4' is a real pain in the rear.
Erik Forbes
No doubt! It's funny how awkward it is when they get to four.
Peter Nore
+1  A: 

I might try paring down some of the later chapters of SICP, but at very least, perhaps the chalkboard might be the most simple way of doing it.

I'd start with first principles, Show a bit about the common logic gates, and, or, not, then show how they can be put together to produce addition, again all on the chalkboard.

A flip flop would also be a very good example of the lowest level of computer circuitry.

A simple chalkboard demonstration of binary arithmetic should seal the deal.

There's not much else in a CPU that's not made of these parts (or something comparable)

If it were up to me, I'd make sure that this is an actual part of the lesson plan, spend maybe half a lesson on it. Understanding some of these basics is really fundamental to any kind of successful programming.

TokenMacGuy
+3  A: 

One simple way to start is by teaching some assembly. Pick a simple CPU and just do it. Make it optional if you like, but it's really not that hard. Without knowing assembly, understanding a CPU is tough.

I taught myself assembly the summer before 10'th grade (got my TRS-80 when I graduated JR High). You'd think with any help (or a better book than a z-80 technical manual) I would have been able to pull it off in Jr. High.

If necessary go dig up a really trivial assembly-style language somewhere that just does some basic operations.

Once they have an overview of how assembly works (bitfields, instructions and registers at least), you might try to have children act out the different parts of a CPU and implement a few simple instructions.

Instruction Pointer has one job, remember what is the next instruction.

The IP "points" at a memory location (another kid) who gives his piece of paper to the bus.

The bus gives the paper to a register to hold (the paper/cpu instruction should say which register it goes to, of course)

Repeat for another piece of data in another register.

then the third would be an add instruction telling him to grab stuff from the two registers and hand them to an adder.

The adder would calculate an answer and return the information to the bus

Etc.

Showing how painfully simple every part of the operation is (even the math is trivial if they consider how easy adding in binary is (Going through a 2-bit binary adder might be fun as well); then impressing on them how fast a computer does these things might get the point though.


That said, the things I had to learn to really understand a how a CPU works were:

  • Assembly Programming including Registers, Pointers (like Instruction Pointers), indexes, ...
  • and/or/not/... Gates, how they can be combined to make addition possible, and also how they could be used to implement a simple instruction decoder (Use a bitfield to raise a signal that causes a single register to store data that is currently on the data bus)
  • Flip-Flops--I know they are just a combination of logic gates, but specifically how they can be combined to store data. (black-boxing a gate by thinking of it as a relay helped me)
  • The Bus--The concept that data is "Dropped" on the data bus, then snagged by whoever is addressed and told to go pick it up.

And I actually didn't pick up the last critical piece until I was in the navy, how the timing signal interacts with the rest of the system to control the flow and how everything is clocked through the system.

Bill K
I like that about acting the whole thing out. Wish I could give you +2 for that one. :-)
SoapBox
+1  A: 

I'd probably take a a much more top-down approach, probably going with computer architecture rather than just the CPU. I'd say something to the effect of:

There are a few basic parts of any computer; these are the CPU, the memory, and the input and output. The CPU will load an instruction from memory, and depending on what the instruction says, it might perform addition, subtraction, or some other operation, or it might get input and save it to a variable or generate output. The next location in memory is saved by a "program counter," which works in a similar way to line numbers in a piece of software. Then, when the instruction is done executing, the program counter is incremented and the next instruction is executed.

At this point, I'd draw out (or have drawn out) a very simple computer architecture on the board. I wouldn't draw logic gates; I'd draw enough "blocks" to implement the following instructions: load, add, subtract, and output. I wouldn't have registers; only a block of 8 memories, which would just be lines in a table. Load would take a memory location, and value as its arguments. Add and subtract would take two memory locations. Output would take a memory location, and you could "wire up" a display or something.

I'd then draw lines between blocks, add in a mux that chooses the path based on the operation, or if the numbers should go to memory (kids can understand switching between inputs in my experience). At this point, I'd show them how I'd add 5+10 or something, and what happens to the data.

Finally, I'd say that a high level language like Java gets reduced by the Java interpreter into smaller operations (avoid the word compiling), and that's what gets executed on the hardware.

My knowledge of pedagogy isn't very strong, but this is how I learned how a calculator worked. I was pretty young and picked up most of it from a logic introduction in an Amiga magazine...

Jeremy CD
A: 

dmckee's mention of the Chinese Room metaphor is a good one. If you or your students are interested, Jon Stoke's Inside The Machine is a fantastic book and goes into a fascinating level of depth. If you can read the first three chapters (just spend a little time at the local library, perhaps) you may get a much better idea of how to explain things. It builds up a little CPU as it describes the basics so you'll understand what comes later.

You can give them the basic "computers do math" stuff. I'd like to try to offer some suggestions on some of the bigger parts of all this. As others have mentioned, I'd suggest discussing something really simple like an 8086 or 6502. In fact, the 4004 may even be a good idea because it's so simple.

The main thing I'd try to tell them is how a CPU is basically a pipeline. Now each stage happens concurrently, but of course they didn't used to. A demonstration is probably best.

A simple CPU does one thing at a time. To execute an add it first gets the two numbers from memory, then adds them, then stores the result. The registers they use can be thought of as on CPU memory, that only stores one number at a time. You could demonstrate this by giving someone a box of cards with how to execute instructions. Someone would pass them an instruction (ADD) and two numbers (3 and 7). They would look up how to execute the instruction in the box (following the right path in the CPU), do each step, then hand the answer out.

Each instruction turns into a number. Code just turns into a list of numbers. You read a number, execute it, repeat. Showing them what assembly ends up as (i.e. the first byte is the instruction, the second and third may be data) may help with this. Where you are in the execution of the program is just the program counter, which is just another number in memory, an index into an array.

How the CPU works seems complicated, especially on modern CPUs. But it really is just a handful of very simple parts working in a predefined order. The most complex parts that exist today (like the branch predictor, cache algorithms, etc) all exist as icing to make the chip perform fast. They are totally unnecessary for the CPU to work correctly.

I took a quick look at the block diagram of the Intel 4004, you can see it on Wikipedia here. As you can see it's very simple. It's about the best you can get to break things down in a real chip. The chip's datasheet contains the list of all the opcodes and how the binary representations of the instructions are created. This occupies all of 3 pages. It's very simple for what it is. With the information in this sheet as well as a basic understanding and a diagram on the board you should be able to step through executions of things and give a basic idea.

I don't know how much binary math they know, but giving them at least an overview of adding (just base 2 math), AND, and OR should be enough to "get" it.

I hope this all helps. It took me a couple of years to really start to get it, trying to teach myself based on my already existing programming knowledge and Z80 assembly (since I was trying to program my TI-85).

MBCook
+1  A: 

Maybe a good way to start would be by a description of a Turing machine. See Wikipedia for a succinct definition, and a few words like head, tape, table I am referring to. That should take about 100 words or less, and is graphically very easy to understand.

Then you could use that to explain that a modern microprocessor (say, the one in your home microwave) works on the same principles, but is a bit more complicated: more complex data (N bits instead of just one), wider instruction set, and the ability to use, and reposition, read/write "heads" in addition to the one that marks what you are executing (in computing jargon, the PC). There is also a predefined number of heads, that you can access and operate on more easily (registers). They should not meet any big conceptual roadblock there.

Then get to the main point by saying that a computer CPU is more of the same, but with several, interacting tapes, that have various priorities (those are interrupt levels, and admittedly are more a computer architecture topic). No need to get very complex there, as most discussion point will refer to computer architecture (or probably even more specifically, to the PC architecture) which is out of the scope (and would be far more complicated to explain).

Varkhan
A: 

I may be showing my age here, but I took a high school computer course back when we were very excited to have 286 machines in the new computer lab.

The first thing that the teacher taught us was the binary counting system, including how to:

  • Store a positive number in binary
  • Store a negative number in binary using two's complement
  • Add two positive numbers in binary to get another positive number
  • Add a positive and a "negative" twos complement number to do simple subtraction

Once you know that:

  • You have to explain what a flip-flop is. This explains how you can store a 1 or a 0 electronically. Explain that this is why binary is important in computers, because we have an easy electrical representation for binary (on and off).
  • You also have to give them a basic understanding of logic gates and that each one can be implemented as an electrical circuit

Then:

With that, you can explain how you could do addition and subtraction on binary numbers using electrical circuits. Then you can explain that one byte is stored in 8 flip-flops so a gigabyte of memory is about a 8 billion flip-flops all stuffed together on a tiny microchip (not exactly true of main memory, but it is true of internal CPU registers). Similarly, logic gates are down to under 50 billionths of a meter, so you can pack a whole lot of adders and other arithmetic circuits onto a microchip.

Then I'd teach them assembly language, but you did say 500 words or less...

Scott Whitlock
A: 

When I was in 1st year uni, they explained it to us by use of the Little Man Computer metaphor.

nickf
+1  A: 

I've always liked the "CPU as a factory" analogy where binary data is carted in and out of the ALU, and instructions are pulled in to tell the ALU what to do with the data (add, subtract, etc).

But I also agree with others that its difficult to understand the CPU without some surrounding context, specifically:

  • Math operations in hardware - perhaps show how a half adder works and then have them take it on faith that other operations can be done with more complicated circuits.

  • A processes structure in memory - to see that everything is binary numbers, and the difference between data and instructions is their location.

  • Context Switching - In my studies, this one really tied it together for me. A quick explanation of how the CPU can switch processes to seemingly do many things at once.

rogueg
A: 

I think the MIPS CPU is relatively simple enough to go through. Wikipedia's picture of the 5 stages may be overkill so you can try a smaller example like the ones here (PDF, with more resources here). Basically explain some basic assembly instructions, talk about the registers, describe the datapath, and other similar topics. Describe each topic using simple real-life example and maybe translate a simple high-level language into actual MIPS (there are tons of examples online) then walk them through the datapath. You can also get into the hardware details but I'm not much help there.

nevets1219
+9  A: 

Here's my take on it -- it may not be comprehensive, but it's 499 words.


The central processing unit (CPU, or processor) can be said to be the "brain" of the computer - it performs calculations and decides how it should behave at certain times according to commands set forth in a series of instructions called a program. The instructions are executed by the processor in the order they are written in the program.

Different parts of a program can define different types of actions which can be performed by the processor, be it calculating an average of numbers, displaying a greeting, or not doing anything. In many computer architectures, there are jump instructions (or branch) which will permit the processor to move from one section of a program to another in order to accomplish different tasks.

The processor will receive information that it will act upon as data from external sources, the main memory. (Although modern processors will have multiple types of memory, some of which is on the processor itself, called the cache, but for all intents and purposes, they can be thought of as an way to access data from the main memory in a faster way by having a local copy in the processor.)

The data will be used the processor to perform calculations and also to decide when to jump to other parts of a program. The processor can only hold onto a few data items at the same time, similar to how people can't remember many things at the same time. In most processors have a temporary storage area called registers which are used to store data which are acted upon in an immediate fashion. For example, when adding the values 1 and 2, those two values (or data) will be loaded into registers, and the processor will be told to add them. The result may end up in another register.

One of the most important actions of a processor is to changing the program execution flow. As mentioned earlier, this can be accomplished by jumping to different parts of a program. In many cases, a we want to jump to a different part of a program depending on different conditions. For example, we may want to stop the execution of a program when the result of a subtraction is 0. In that case, we could utilize a conditional jump, which will cause the processor to jump to another part of a program when the result of a calculation was zero.

The processor keeps track of what part of the program is being executed by holding onto a line number of the program that it is executing. This is sometimes called the instruction pointer which points at the location of the program the processor is executing. When the program jumps, the pointer is changed to the program location the execution should jump to.

By combining simple operations and calculations, a processor can make the computer perform many tasks. The individual instructions are trivial, but at the speeds computers operate at, the tasks they can perform almost seem like magic.

coobird
A: 

I did a search and can't find one, but it seems to me like there should be a CPU emulator out there that shows all the parts of a cpu in a visible format. Even allows for processing some simple instructions.

Although I'd use block diagrams for different parts of the CPU, I could even see zooming in to see logical flow of an instruction--like the gates used for an adder, or registers and clock cycles.

I can't believe nobody has done this, it's not hard and would be great for young people trying to understand a computer.

It could even have a little assembler to show how instructions are encoded and the resulting bitfields are used to specifically trigger parts of the CPU. This could be quite the work of art if done right, and could be made to be understandable by virtually anyone with an interest.

With a very simplified instruction set, it might even be possible to implement the instruction decoder with gates and not use an interior micro-language as I believe most CPUs today use.

So this is more a sub-question than an answer--has anyone seen such a monster?

You'd think a grad-student in CPU design would have done so by now.

Bill K
+6  A: 

Zork

You find yourself in in front of a wall that seems to go on forever. On close inspection, the wall is made up of numbered pigeon holes. On even closer inspection, each pigeon hole contains a slip of paper. You feel a terrible compulsion to take the slip out of the nearest pigeon hole. On it, you find the the words "Go to the pigeon hole 500 places to the right and do whatever is written on the slip in that pigeon hole".

The adventure has begun....

anon
A: 

Just don't. Explaining a CPU with words is just foolish. You need images and animations to explain it.

John Nilsson
A: 

An answer for the 12 year old.

Ultimately, a CPU follows a set of programmed instructions one-by-one, executing a few simple actions in rapid succession:

  1. It can do math, in varying degrees of complexity.
  2. It can move information from one place to another.
  3. It can store and retrieve information, including program instructions.
  4. It can make yes/no decisions by comparing two numbers.
  5. It can jump to a different part of its program.

The reason a computer seems so smart is that the CPU can perform millions of these tiny actions very rapidly. By combining large numbers of these actions in complex patterns, computers can be programmed to do some very interesting things.

Robert Harvey