1. Home
  2. Explore
  3. Computer Science
  4. Building a Simple Computer

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Building a Simple Computer

Speaker 1Speaker 2

Building a Simple Computer

11:28
0:00-11:28
  1. Corey

    Welcome back to our tour of how computers work. So far, we’ve built two four-bit registers, each able to hold one number, and an ALU that can add or subtract them. For example, we can put 15 in one register and 10 in the other, choose subtraction, and pulse the clock to store the result. That’s a useful start, but it’s nowhere near a general-purpose computer—and we’re running out of room in the old simulation.

  2. Maria

    So the new simulation gives us more room to build?

  3. Corey

    Exactly. It looks similar, but its input pins are standalone, so we can zoom and move around the workspace. There are also four-bit and eight-bit input pins, which save us from wiring every bit individually. Our next project is main memory: a much larger place to store values and retrieve them later, rather than keeping only the handful of numbers currently in registers.

  4. Maria

    Why not just build that memory out of the registers we already have?

  5. Corey

    A register is made from several one-bit registers, but each one includes logic for synchronizing with the clock. Repeating all of that for every bit of a large memory would be wasteful and potentially slow. We can instead start from a simpler building block: a latch made from two NOR gates, with each gate’s output fed back into the other gate’s input. That feedback holds one bit in place.

  6. Maria

    So the basic idea is to build lots of those one-bit latches, then select the one we want?

  7. Corey

    Right. Let’s begin with a four-by-four grid, giving us 16 latches. Selecting one out of 16 requires a four-bit address. We can divide it into two bits for the row and two bits for the column. A particular latch is selected only when its row and its column are both selected.

  8. Maria

    And the address decoder turns those two-bit row and column values into individual selection signals?

  9. Corey

    That’s it. We make a decoder with two input bits and four outputs, one output for each possible input value: zero, one, two, or three. To detect zero, invert both inputs and feed them into an AND gate. To detect three, AND the inputs directly. For two, the first bit is off and the second is on; for one, it’s the other way around.

  10. Maria

    So each decoder output means, in effect, “this particular row” or “this particular column” is active. Then combining one row signal with one column signal selects a single intersection.

  11. Corey

    Exactly. We use one decoder for the rows and one for the columns. Rather than repeat the selection and storage wiring by hand for every latch, we package it into a one-bit memory cell. The cell has data and store inputs, plus row and column selection inputs.

  12. Maria

    What does that cell do with those selection signals?

  13. Corey

    An AND gate checks whether both its row and column are active. If the cell is selected and the store signal is on, it writes the input data into its latch. For reading, we also need to stop unselected cells from driving the output. A three-state buffer does that: when the cell isn’t selected, its output is disconnected—not a zero or a one.

  14. Maria

    And when both selections are active, the buffer lets the latch’s value through?

  15. Corey

    Yes. The latch’s initial value can be random, but we can store zero or one and see the output reflect it. We’ll call this one-bit cell MEM1. Real memory cells are much more optimized than our simulation; the source notes that some use as few as six transistors. Exploring those designs properly would take a more advanced simulation.

  16. Maria

    There are also different physical ways to make memory, right?

  17. Corey

    Right. The latch-based approach is called static memory, or SRAM. It’s very fast, but takes up quite a lot of physical space, so it’s used for relatively small memory chips—up to a handful of megabytes, as the example puts it. Much larger memories, in the gigabyte range, are typically made with capacitors instead.

  18. Maria

    A capacitor stores a bit as charge: charged is one, and empty is zero?

  19. Corey

    That’s the basic picture. A capacitor can hold charge after the input power is removed, but reading it discharges it, and the charge also leaks away over time—at tiny scales, in fractions of a second. So dynamic memory, or DRAM, needs extra circuitry to repeatedly read and rewrite its contents. The trade-off is compactness: a bit can be stored using one capacitor and one transistor to control access.

  20. Maria

    And both static and dynamic memory need power to retain their contents?

  21. Corey

    Yes. They’re both volatile: without a constant power source, the data is lost. For long-term storage, information has to be transferred to persistent memory, such as a hard drive that stores data by changing the magnetic polarity of tiny regions on a spinning disc.

  22. Maria

    Back to our simulated latch grid, then. How does the one-bit cell become a useful block?

  23. Corey

    We place 16 MEM1 cells in a four-by-four grid and connect each row and column to its decoder. Every cell also receives the shared data and store signals. Since only one cell can be selected at a time, only one output is active, so we can join the output wires together into a shared line.

  24. Maria

    But you mentioned making this block usable inside a bigger grid. Does it need another level of selection?

  25. Corey

    That’s the key bit of planning. We give the 16-cell block its own row and column inputs, too. AND gates combine those to decide whether the whole block is selected. When it is selected, the block can store data or pass its output along; when it isn’t, its output is disconnected. Testing confirms that the row and column address bits select the expected cells, and that an unselected block neither outputs nor stores data.

  26. Maria

    So that block contains 16 bits, with its own selection inputs—ready to be one entry in a larger memory.

  27. Corey

    Exactly. We call it ME16. Now we arrange 16 ME16 blocks in another four-by-four grid. The top four bits of an eight-bit address select one of those blocks, and the bottom four bits select one of the 16 bits inside it. That gives us 16 times 16, or 256 addressable bits.

  28. Maria

    Which is still a lot of individual bits to work with if we want to store ordinary numbers.

  29. Corey

    Right. We duplicate that memory structure eight times, one for each bit of a byte. Now we have 256 bytes of data. An eight-bit address selects which byte we’re looking at, and an eight-bit data input lets us store a value there. We can also connect the output to an eight-bit pin and a decimal display.

  30. Maria

    So if we store 150 at address 255, move to another address and store something else, then return to 255, the original 150 is still there?

  31. Corey

    That’s exactly the test. Each address keeps its own stored value, and changing the address lets us retrieve the corresponding byte. The real-life demonstration does the same thing: it stores a value at one address, visits another, and returns to find the first value waiting.

  32. Maria

    This is called random access memory because we can jump to an address without having to work through the locations in order?

  33. Corey

    Yes. For this kind of memory, moving from one address to another takes the same amount of time, regardless of which addresses we choose. That contrasts with a hard drive, where the disc has to spin and the arm has to move, so access time depends on where the data is.

  34. Maria

    But the name RAM doesn’t mean programmers never care about the order of memory accesses.

  35. Corey

    Correct. Computers often have a large amount of slower dynamic RAM and a much smaller amount of very fast static RAM close to the CPU, called cache. When data is requested, the computer checks the cache first. If the data isn’t there, it fetches it from main RAM and brings along nearby data, hoping the next request will be for one of those nearby addresses.

  36. Maria

    So nearby future requests may be served from the faster cache instead of making another trip to main memory.

  37. Corey

    Exactly. We won’t model cache here, but it’s useful context. There’s another issue with our simulated RAM, though: it’s asynchronous. Its address and store inputs aren’t synchronized to a clock, so if store stays on while the address changes, we could accidentally overwrite values at the wrong addresses.

  38. Maria

    That’s manageable while a person is carefully moving switches, but could cause trouble when other computer components control those signals.

  39. Corey

    Right—potentially creating race conditions. The first fix is to put registers in front of the RAM’s address and data inputs. These are built from one-bit registers with clock synchronization. Their inputs take effect only on the clock’s rising edge, when the clock changes from low to high.

  40. Maria

    So changes to the input pins don’t immediately reach RAM; the registers hold their values until the next rising edge?

  41. Corey

    Yes. We let the address register update whenever the clock pulses, but only enable the data register to update when store is on. That way, the RAM receives registered address and data. In the simulation, that makes writing behave much more predictably.

  42. Maria

    But if we’re only reading, we’d have to wait for the next clock pulse before the RAM sees a new address.

  43. Corey

    That’s inconvenient, so we improve the arrangement. The RAM gets the address directly, which lets its output respond immediately. To protect writing, we allow a store only when the store signal is on and the direct input address matches the address held in the register.

  44. Maria

    How do we tell whether those two eight-bit addresses match?

  45. Corey

    First, make a one-bit equality test. XOR is high when its two inputs differ, so invert its result to get XNOR, which is high when the inputs match. Then use eight XNOR gates—one per bit—and AND their results together. The final output is high only when all eight pairs match.

  46. Maria

    Then the current address can control reading right away, but writing is permitted only if it agrees with the clocked address.

  47. Corey

    Exactly. The test shows that changing addresses updates the output immediately, but doesn’t overwrite other locations even if store remains on. We can pulse the clock to store, for example, 42 at address 85, and then verify that a value at address zero is unchanged.

  48. Maria

    And changing data without a clock pulse, or pulsing the clock with store off, leaves the memory alone.

  49. Corey

    Right. That gives us a much better-behaved RAM for the simulated computer. There’s a real-world timing caveat: physical signals take time to settle. If store is already on while the address register’s output is still changing, the RAM could briefly see an unstable address.

  50. Maria

    So the simulation’s assumption that all the signals arrive settled together is more forgiving than actual hardware.

  51. Corey

    Yes. One possible solution is to register the store signal too, with extra logic to delay it by a clock cycle so the address has time to settle before writing is enabled. For this simulation, though, the signals are treated as arriving together, so the simpler setup works.

  52. Maria

    And we can trace the design back down through its layers: eight byte-wide groups, then the 16-bit blocks, then the 16 one-bit cells, and finally the latch.

  53. Corey

    That’s the memory journey in a nutshell. The address decoders select a location, the latches hold the bits, and the larger grids turn those bits into addressable bytes. We’ve come a long way from two small registers and an ALU, and this memory gives the computer somewhere to keep results for later.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent