Ask HN: Why a Computer Need a “Memory”?
So, you seem to be laboring under some drastic misunderstandings.<p>Let me try to lay out an example that may make things clearer.<p>I have a CPU.<p>A CPU consists of a collection of general registers (data is generally read from and into here), a special set of registers containing metainformation about the state of the CPU, an arithmetic processing unit, and a clock circuit. This is a dirt simple CPU.<p>Now. If you&#x27;re using a Von Neumann based architecture, your CPU doesn&#x27;t distinguish data from instructions. (Modern ones do, but ignore that for now.)<p>An &quot;instruction&quot; consists of an op-code (basically a number), plus addresses indicating where input data is being read from, and where it&#x27;s being written to.<p>So a set of commands for this CPU might look like<p>load $1 1
load $2 1
Add $1 $2 $3<p>Assuming we&#x27;re &quot;wired&quot; into some input pin the CPU knows to listen to, we&#x27;re running a rudimentary set of computations. We&#x27;re sending in some number that the CPU recognizes as the beginning of a &quot;load&quot; command, it looks at the 8 bits or so following, and loads 00000001 into register $1. Done for that cycle.<p>Next cycle, same deal, but in register $2.<p>Next cycle, we send the contents of $1 and $2 to the adder, which outputs the result into $3.<p>Easy right?<p>Now. Let&#x27;s do some REAL computation. Let&#x27;s say I have a ridiculous amount of data to crunch.<p>I have 30 8 bit registers for general use, and my 5 or 6 special registers, and my input pin.<p>But I have 300000000000000 8 bit numbers that I want to add!<p>I can make this work with just the CPU logic. I can do a bunch of serial computations, then record the results by hand, and re-input that result as an input to the next computation over and over again, But dear God, that&#x27;s boring!<p>Wouldn&#x27;t it be great if somehow, I could stage all of my information ahead of time, and somehow have the processor look up that information to do it&#x27;s calculating, with out me having to remember everything for it?<p>The answer to that conundrum is Random Access Memory. It&#x27;s a separation of concerns if you will.<p>CPU&#x27;s do computation. That&#x27;s what they are for. Doing the stuff that might cause a state change. We don&#x27;t want values sticking around in the processor that aren&#x27;t changing if we can help it. Once something is done we want it out of the processor so we can accommodate the next state changes.<p>In CS, we tend to have two main axes on which we measure the footprint of computation: CPU time, and space (memory footprint).<p>If I have high space constraints, I can set up the CPU to handle all the state, but for every new computation, I have to reset everything back to basics, and still keep track of all my information. This quickly turns a simple one cycle operation into many cycles worth of operation and bookkeeping about where everything is.<p>Or, If I have memory to write to, I can do my computation, write it out to somewhere that&#x27;s memory managed, and let the magic Memory Management Unit feed me new data and instructions while also cleaning up results, and holding onto them elsewhere on the motherboard so I can use my full CPU die to do computations more quickly.<p>Look at it like having a helper to get books for you at a library while you&#x27;re sitting at home reading books and doing math problems.<p>The library is RAM, you are the CPU, and your home is the CPU cache. Without your helper fetching books for you, you have to stop all the time, and take the books you&#x27;re done with back, check out new ones, go home, and only then start doing math again. (You&#x27;re not independently wealthy, or psychic, so absurdly big house, or magical access to all of the books by telekinesis is not allowed, sorry!)<p>With your helper, you&#x27;re doing math (yay!), and he&#x2F;she&#x27;s swapping out books to&#x2F;from the library to keep you running smoothly.<p>Try not to get caught up thinking about wires. Circuits have about as much to do with  Computer Science as a scalpel does to Surgery. They&#x27;re a tool. Nothing more. The important thing is to understand how all the pieces work together to create a functional whole.<p>If you&#x27;re still confused about why RAM is a thing, let me introduce you to<p><a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;ENIAC" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;ENIAC</a><p>A computer that, quite literally, was absolutely dependent on the people around it to play the role of &quot;memory&quot; since each computation required rewiring the damn thing.<p>Ain&#x27;t nobody got the patience for that anymore!