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 like a set of pigeonholes 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 cards (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 take a pair of knitting needles and place them in the first and third holes counting from the right - i.e. the holes corresponding to the positions you want a zero in.
Now lift up the needles together and the cards left behind have to have zeros i.e. slots in both of those positions.
That is the cards that are left behind all have addresses like x0x0 where x is zero or one.
With this subset of cards repeat the procedure but now place a single needle in the fourth position from the right and lift out a subset of cards. These now correspond to the address 10x0 and so finally you can put the needle through the second position from the left and lift out the only card with the address 1010.
This is a completely general procedure and any card that you are looking for can be found in the same way. First use multiple needles to pull out cards with the required zeros and then use a single needle to reduce the deck to the cards with the required ones.
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 memory principle is that you store data at an address for later retrieval and presenting the address to the mechanism automatically retrieves the correct data. In other words the address physically selects the data returned it isn't just a passive label.
What has modular arithmetic got to do with the real world? The answer any experienced programmer should give you is "a lot". Not only is it the basis for many an algorithm, it is part of the hardware. [ ... ]
This week's cartoon is based on the use of RPN or Reverse Polish Notation. This used to be a basic of the computer programmer's world, but today it is not as well known. Hence there may be some perfec [ ... ]