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

Building Addressable Memory

From Registers to Main Memory

A register stores a small amount of data that a computer is actively using. The computer developed so far has two 4-bit registers, each capable of holding one 4-bit number. An arithmetic logic unit (ALU) can take the values in those registers and perform addition or subtraction, with the result stored in another register.

Registers are useful for immediate calculations, but a general-purpose computer also needs main memory: a much larger storage area in which it can keep many values and retrieve them later. Building that memory from complete registers would repeat clock-control circuitry for every stored bit. A more compact approach is to build memory from simpler one-bit storage elements.


One-Bit Storage: The Latch

A latch can store a single bit. In the simulated design, it is constructed from two NOR gates whose outputs feed back into the opposite gates’ inputs. This feedback allows the circuit to retain one of two states: a low signal or a high signal.

A latch can serve as the basic storage element for a larger memory. However, a memory also needs a way to choose which latch to access, determine when data may be written, and prevent unselected latches from interfering with the output.

Selecting a latch’s output

A three-state buffer allows an output to have three possible conditions:

  • A high logic level

  • A low logic level

  • A disconnected, or high-impedance, state

When a latch is not selected, its output can be disconnected. When it is selected, the buffer passes the latch’s stored value to the output. This arrangement allows several memory cells to share an output line, provided that only one cell is enabled at a time.


Address Decoding

A memory address identifies which stored location should be accessed. For a small memory arranged as a grid, the address can be divided into row and column components.

A grid with 444 rows and 444 columns contains 161616 locations. Selecting one of those locations requires a 444-bit address, because 444 bits can represent 161616 distinct combinations:

24=162^4 = 1624=16

The address can be divided into two 222-bit values:

  • One value identifies the row.

  • The other value identifies the column.

Two-bit decoder

A decoder converts a binary input into one active output corresponding to that input’s value. A two-bit input has four possible values, so a two-bit decoder produces four outputs: one for each value from 000 through 333.

Each output is made active by checking the appropriate combination of input bits:

  • For input 000, both input bits must be low.

  • For input 111, the first bit must be high and the second low.

  • For input 222, the first bit must be low and the second high.

  • For input 333, both input bits must be high.

In the circuit, AND gates detect the required combinations, and inverters provide low-going versions of the input bits where needed. Separate decoders can select the row and the column. A particular memory location is selected only when both its row and column are active.


A Selectable One-Bit Memory Cell

A reusable one-bit memory cell combines a latch with selection and write-control logic. It has inputs for:

  • Data: The bit to be stored.

  • Store: The control signal that permits writing.

  • Row and column selection: Signals that indicate whether this cell is addressed.

The row and column signals are combined to determine whether the cell is selected. Data is written to the latch only when the cell is selected and the store signal is active. The latch’s output is passed through a three-state buffer, so it appears on the shared output line only while the cell is selected.

This creates a useful behavior:

  • An unselected cell does not output a high or low value; it is disconnected.

  • A selected cell outputs the value held in its latch.

  • A write affects the latch only when the cell is selected and storing is enabled.

The latch’s initial state may be arbitrary. In practical memory, stored data is meaningful only after it has been written.


Static and Dynamic Memory

The latch-based cell illustrates static RAM, or SRAM: memory that stores data in a circuit state maintained by feedback. It is fast, but each bit requires a relatively large circuit compared with some other memory technologies.

Static RAM

  • Stores data in a latch-like circuit.

  • Is fast and does not need the same repeated read-and-rewrite refresh process as dynamic RAM.

  • Uses more physical space per bit, making it less suitable for very large capacities.

  • Is commonly used for small, fast memory such as a processor’s cache.

Real SRAM cells use carefully optimized transistor circuits. A typical cell may use as few as six transistors, rather than the larger collection of logic gates in a simple teaching simulation.

Dynamic RAM

Dynamic RAM, or DRAM, stores each bit as electrical charge in a capacitor. A charged capacitor represents one state, and an uncharged capacitor represents the other. A transistor controls access to the capacitor.

DRAM is compact because a bit can be stored using a capacitor and an access transistor. It has two important drawbacks:

  • Reading a cell discharges its capacitor, so the value must be restored after it is read.

  • The charge leaks away over time, so it must be refreshed repeatedly, on a timescale that can be a fraction of a second at small scales.

Memory controllers therefore continually read and rewrite DRAM contents to preserve them. DRAM’s compactness makes it suitable for large amounts of main memory, even though it requires refreshing.

Volatile and persistent storage

Both SRAM and DRAM are volatile memory: they require power to preserve their contents. When power is removed, the data is lost.

Persistent storage retains data without continuous power. A hard disk, for example, stores information by changing the magnetic polarity of tiny regions on a spinning disk. A movable arm positions the read/write mechanism over different regions. This mechanical movement makes access slower and dependent on the disk’s physical position.


Combining Cells into Larger Memories

The memory design grows by grouping smaller cells into larger structures. Each level adds address bits to select among its component locations.

A 4×44 \times 44×4 grid: 16 bits

Sixteen one-bit cells can be arranged in a 4×44 \times 44×4 grid. Two decoders select a row and a column, and the selected cell’s output is connected to the shared output line.

The grid also receives a data input and store signal. Only the selected cell should accept the write operation, and only the selected cell should drive the output. Because the output buffers disconnect unselected cells, all cell outputs can share one line without their values interfering.

This grid stores 161616 bits:

4×4=164 \times 4 = 164×4=16

The grid itself can be designed as a reusable memory cell, with row and column inputs that allow it to be selected inside a still larger structure.

A 4×44 \times 44×4 grid of 16-bit cells: 256 bits

Sixteen 16-bit grids can be arranged in another 4×44 \times 44×4 grid. This larger structure uses an 8-bit address:

  • Four address bits select one of the sixteen 16-bit cells.

  • The remaining four bits select one of the sixteen individual bits within that cell.

The total capacity is:

16×16=256 bits16 \times 16 = 256 \text{ bits}16×16=256 bits

At this level, only one small cell is selected at a time. Its output can therefore be connected to the larger structure’s shared output line.

Building byte-wide memory: 256 bytes

A bit stores only one binary digit, but computers commonly work with bytes. A byte contains 888 bits. Eight parallel copies of the 256-bit structure can be used to store and output eight bits at each address.

This produces 256256256 bytes of memory:

256 locations×8 bits per location=256 bytes256 \text{ locations} \times 8 \text{ bits per location} = 256 \text{ bytes}256 locations×8 bits per location=256 bytes

An 8-bit address selects one of 256256256 byte locations, since:

28=2562^8 = 25628=256

The selected byte can be displayed as a binary value or converted to decimal. Each address retains its own data: writing to one address does not overwrite the values stored at other addresses.


Random Access Memory

Random access memory, or RAM, allows the computer to access any address without first passing through all the preceding addresses. In the simulated memory, the time to select one address is the same as the time to select another, assuming the controls are not being operated manually.

This differs from a mechanically accessed hard disk, where the time required depends in part on how far the disk must spin and how far the arm must move.

The term random access describes the ability to select locations directly; it does not mean that software must access memory locations in a random sequence.

Cache and main memory

Computers commonly use a memory hierarchy:

  • Cache: A relatively small amount of fast SRAM located close to the processor.

  • Main memory: A larger amount of comparatively slower DRAM.

When data is requested, the processor checks the cache first. If the data is not there, it retrieves it from main memory. The system often brings nearby data into the cache at the same time, on the expectation that the processor will soon need it.

This approach makes data access faster when later requests use information near a recently accessed address. Consequently, programmers and system designers may consider the order and locality of memory accesses, even though RAM can directly select any address.


Asynchronous RAM and Timing Risks

The basic RAM design is asynchronous: its output responds to the current address without waiting for a clock edge. Its write operation is controlled by the store signal, but the design is not inherently synchronized with the rest of a clocked computer.

This creates a risk. If the store signal is active while the address changes, the RAM may write data to an unintended location. Manual operation can avoid this by carefully controlling the signals, but signals controlled by other computer circuits can change at inconvenient times. Such timing problems can lead to race conditions.


Adding Clock Synchronization

A clocked register can hold the address or data steady for the RAM. In the design, each 8-bit register is assembled from eight one-bit registers.

The register captures new input data only on the clock’s rising edge, when the clock changes from low to high. Changes to the inputs while the clock remains high or low do not alter the stored value. This allows the register to present a stable value between clock edges.

A simple synchronized arrangement uses:

  • An address register to hold the address.

  • A data register to hold the value to be written.

  • A store signal to control whether the data register is updated and whether RAM writes.

  • The register outputs as the RAM’s address and data inputs.

The data register updates only when storing is intended. The address register may update regardless, so its store control can be kept active. RAM then receives stable registered values rather than directly tracking changing inputs.

Timing caveat in real hardware

Real circuits do not change instantaneously. Signals take time to settle after a clock edge. If the store signal is already active while the address-register output is still settling, RAM could briefly see an unintended address.

A safer design can register the store signal as well and delay it by a clock cycle, giving the address time to stabilize before writing begins. The simplified simulation assumes signals arrive together and settle ideally, but real circuits must account for these timing constraints.


Reading the Current Address While Protecting Writes

Waiting for the next clock pulse every time the address changes can make reading RAM inconvenient. The design can instead send the current address directly to RAM for reading, while using the address register to control whether writing is allowed.

An equality check compares:

  • The current input address.

  • The address stored in the register.

The RAM may write only when the store signal is active and the two addresses match. This provides two useful behaviors:

  • The RAM output responds directly to the latest input address.

  • A write is permitted only for the address that has been registered.

Building an 8-bit equality check

Two single-bit values are equal when they are both low or both high. An exclusive OR (XOR) detects whether two bits differ; inverting its output produces an exclusive NOR (XNOR), which is high when the inputs match.

For an 8-bit comparison, eight XNOR gates compare corresponding pairs of bits. AND logic then checks that all eight comparisons indicate a match. The resulting equality signal is high only when the entire 8-bit addresses are identical.

This match signal can be combined with the store signal to prevent writes to addresses other than the registered one.

Verifying the synchronized behavior

A useful test checks both reading and writing:

  1. Write a known value to one address by activating store and pulsing the clock.

  2. Change the input address. The output should change to show the newly addressed location, but the active store signal should not overwrite it unless the address matches the registered address.

  3. Turn off store or change the data without clocking the register. The stored memory values should remain unchanged.

  4. Return to the original address and confirm that its previously stored value is still present.

This arrangement produces RAM that is more predictable when connected to clocked parts of a computer.


How the Memory Structure Fits Together

The complete memory can be understood by following its nested construction:

  1. A latch stores one bit.

  2. A selectable one-bit cell combines the latch with row/column selection, write control, and a three-state output.

  3. Sixteen one-bit cells form a 16-bit grid.

  4. Sixteen 16-bit grids form a 256-bit structure.

  5. Eight parallel 256-bit structures form 256 bytes of addressable memory.

  6. Registers and control logic can synchronize writes with the computer’s clock.

Each level uses address bits to select one component, while shared data and output lines reduce the amount of wiring required. The resulting RAM stores many values independently and allows a selected value to be read or updated without disturbing the others.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent