To understand the memory principle it we have to go back to my six-line Fortran program and think a little about how it might work. Well actually Fortran is a little advanced. What we really need is machine code and we might as well use Babbage’s.
His machine stored instructions on punched cards as a pattern of holes. Each card was a single instruction. Now consider a card that holds the instruction:
Store 10 in B
This looks superficially like the instruction to place a pigeon in a particular hole but it is more than this. The holes punched in the card not only mean “Store 10 in B” they actually DO IT. Imagine that resting on the card is a set of rods. Where there is a hole the rod goes through and so moves. The movement of rods into and out of holes is what sets the machine up to do a particular operation and it selects the stack of wheels that the number will be stored in.
In the case of “Store 10 in B” the holes that specify wheel stack B will let rods drop through that physically move it into position so that its, and only its, cogs engage with a gear wheel. The holes that specify the “Store” operation will set the machine up so that gear wheel is driven by the processor and the rods that specify 10 arrange that it will rotate exactly ten times.
I’m going to leave it to your imagination to work out how the last piece of machinery could be implemented but you should be able to see that it is possible. Also notice that the number stored is in fact added to the wheel stack rather than just transferred. It turns out in most computer implementations to be easier to add a value than store it. As long as the programmer remembers to clear, i.e. set to zero, the location before adding this is equivalent to a store operation. This is the reason that some specialised memory locations where arithmetic was performed were, and still are, called “accumulators” - they sum up or accumulate all of the numbers stored in them.
If you want to work out the details of how a “Load A from B” operation might work I’m sure you will see that retrieving data from B is just a matter driving the cog wheel in the opposite direction until the value stored in B is reduced to zero. Of course the same cog wheel could be arranged to drive wheel stack A in the positive direction so adding what was stored in B to A. A “Subtract A from B” instruction could be…
This is getting much to detailed.
I have no intention of building the Analytical Engine and we are in danger of missing the point.
What is important is that you can see that computer memory isn’t like a set of pigeonholes. It has addresses and storage locations but in the case of computer memory the addresses aren’t just static labels.
Computer memory addresses actually do select the memory locations they address and this is very different to just having pigeonholes with labels. It is much more like having a bank of pigeonholes that are all covered by doors. In this case the instruction to store a pigeon in hole 1234 would automatically cause that pigeonhole door, and no other, to open. The pigeon would then fly into the waiting memory location.
The instruction to retrieve the pigeon from location 1234 would again cause just that door to spring open and the pigeon would fly out. I’m sure that you can imagine some wild and wonderful Heath Robinson or Rube Goldberg style mechanical machinery to automatically store and retrieve pigeons – and I wouldn’t dream of denying you this pleasure!
The key point is that in a computer memory the addresses are not just dead and static labels for locations they are active selectors. A computer memory is a mechanism where presenting the address returns the contents of the memory or allows something to be stored there.
How does all this relate to today’s modern computer?
Surprisingly well, as it turns out. I admit that we have got rid of the pigeons but the push rods are still there! In this case the push rods are digital signals that come out of the CPU’s electronics – to find out exactly how it works and some fascinating facts like why a Megabyte is exactly 1,048,576 bytes see How Memory Works.
Modern memory - no push rods and certainly no pigeons
Make your own memory
There is a well-known demonstration of how computer memory works that isn’t as well known today as it used to be. It is an excellent demonstration and it’s fun so find yourself sixteen postcards or similar, a hole punch, a pair of scissors and some knitting needles..
Take your set of postcards and punch four holes in a row close to the top edge of each one. The holes have to line up so you can see through them all when you make a stack of the cards. If you are strong enough and have a good enough punch the easiest way of doing this is to punch all sixteen in one go. Next you have to number each card in binary writing the bits under each hole.
Take a pair of scissors and turn any hole with a zero below it into a U shaped slot (see the diagrams for clarification).
First punch holes in all 16 card (only four shown)
Number the cards in binary and make each zero hole into a slot.
When you put the pack of cards back together you have a working computer memory.
If you don’t believe me I will now tell you how to automatically access a location. Shuffle the cards, because the selection process doesn’t depend on them being in any particular order.
Suppose you want the card corresponding to address 1010. First you take two knitting needles and place them into the set of first and third holes counting from the right (i.e. the holes that correspond to the ones in the address).
Now you lift the knitting needles up, so extracting a set of cards. Clearly all the cards that you pulled from the pack have ones in the first and third locations. With this subset of cards repeat the procedure but now place the knitting needles in the locations that have zeros (i.e. the second and fourth sets of holes). Now lift the knitting needles but this time you should find that only one card is left behind – this is the card with the address 1010.
This is a completely general procedure and any card that you are looking for can be found in just two knitting needle operations.
First place knitting needles in the locations that have 1 in the address and pull out the cards. Second place knitting needles in the locations that have a 0 in the address and pull again to leave just one card behind.
There is also a very simple procedure that can be used to put a shuffled deck of binary cards back into order - can you work out what it is?
Your next project is to automate this procedure using Lego or Meccano and build something that works as fast as a multicore processor!
The caching principle is very general but it is best known for its use in speeding up the CPU. We take a look a the basics of cache memory, how it works and what governs how big it needs to be to do i [ ... ]