Elements of Computing Systems - Sequential Logic and Memory Systems

System Hierarchy and Course Roadmap

  • Hardware Platform Hierarchy:
    • Elementary Logic Gates (Level 1): Built directly from primitive Nand gates.
    • Combinational Chips (Level 2): Intermediate arithmetic and logical units including Adders, Multiplexers, and the Arithmetic Logic Unit (ALU).
    • Sequential Logic & Memory System (Level 3): Construction of clocked memory components ranging from 1-bit Flip-Flops up to multi-kilobyte Random Access Memory (RAM) banks and Program Counters (PC).
    • Computer Architecture (Level 4): Integration of the CPU, RAM, and input/output devices into a unified hardware platform.
    • Software Layer Hierarchy (Levels 5 & 6): Translating low-level machine instructions via Assemblers and Compilers up to high-level virtual machines and operating system abstractions.

Nand to Tetris Hardware Abstraction Roadmap

  • Prerequisite Topics Covered:
    • Binary and decimal number systems.
    • Binary arithmetic operations (Addition, Subtraction, 2's complement representation).
    • Elementary logic gates (AND, OR, NOT, XOR, NAND).
    • Boolean function evaluation and simplification.
    • Arithmetic Logic Unit (ALU) functional design.
    • Combinational circuit design principles.
    • Half-Adders and Full-Adders.
    • Multiplexers (Mux) and Demultiplexers (DMux).

Fundamental Theoretical Framework of Logic Circuits

  • Combinational Logic Framework:
    • Definition: Logic circuits where the output is strictly a pure mathematical function of its present input signals.
    • Mathematical Model:

out[t]=f(in[t])\text{out}[t] = f(\text{in}[t])

*   **Characteristics:**
    *   Time-independent operations.
    *   Output changes continuously and instantaneously in response to input changes (ignoring physical component delays).
    *   The Arithmetic Logic Unit (`ALU`) represents the topmost complex combinational chip.
*   **Inherent Limitations of Combinational Logic:**
    *   **Lack of Persistence:** Cannot store state or maintain bits over time.
    *   **Feedback Restriction:** Feedback loops (feeding a chip's output directly back into its input) are strictly forbidden because they create indeterminate physical oscillation state conditions.
    *   **Fixed Input Width:** Gates can only process inputs of fixed bit-widths (e.g., an `Or4` gate cannot process arbitrary nn-bit streams without dedicated hardware redesign).
  • Sequential Logic Framework:
    • Definition: Logic circuits whose output depends on both present inputs and historical input sequences (state history).
    • Mathematical Model:

out[t]=f(in[t−1])\text{out}[t] = f(\text{in}[t-1])

state(t)=f(input(t),state(t−1))\text{state}(t) = f(\text{input}(t), \text{state}(t-1))

*   **Characteristics:**
    *   Incorporates physical time dependencies into gate evaluations.
    *   Enables state persistence over discrete time intervals.
    *   Forms the foundational model for Registers, Memory banks, Flip-Flops, and Counters.

Physical Time, Delays, and the Synchronization Clock

  • Software Requirements for Time:
    • State Persistence (Variables): Software requires persistent state holding (e.g., variable assignment x=17x = 17).
    • Iterative Execution (Loops): Reusing identical physical hardware repeatedly across sequential loop cycles:
for i = 1..100:
    sum = sum + i
*   Accumulating values across iterations requires reading previous states (sumt−1\text{sum}_{t-1}) to calculate new states (sumt\text{sum}_t).
  • Hardware Requirements for Time:
    • Physical Time Delay: Real electrical components exhibit delay due to finite switching speeds, semiconductor resistance, and stray capacitance.
    • Propagation Delay (tpdt_{pd}): The physical duration required for an electrical signal transition at the input terminal to traverse circuit path gates and fully stabilize at the output terminal.

Multi-Bit Adder Propagation Delay Sequence

*   **Ripple Carry Propagation Example:** In a multi-bit ripple-carry adder, Full Adder stage nn cannot produce a valid carry-out signal (CnC_n) until it receives the carry-out (Cn−1C_{n-1}) from stage n−1n-1. The total propagation delay accumulates linearly across the adder length:

tdelay, total=n×tpd,FullAddert_{\text{delay, total}} = n \times t_{pd,\text{FullAdder}}

  • The Master Clock and Discrete Time:
    • Physical Clock Generator: A hardware oscillator circuit (e.g., a 1.0 MHz1.0\,\text{MHz} crystal oscillator circuit utilizing quartz resonance properties) generating an continuous rectangular voltage pulse train.

1.0 MHz Quartz Crystal Electronic Oscillator

*   **Discrete Time Model:** Converts continuous physical time into integer steps (t=1,2,3,…t = 1, 2, 3, \dots).
*   **Clock Cycle Period (TT):** The time duration between two consecutive rising or falling edges of the clock signal.
*   **Clock Frequency (ff):** Reciprocal of the clock period, measured in Hertz (Hz\text{Hz}):

f=1Tf = \frac{1}{T}

*   **Neutralizing Delays via Clock Cycle Engineering:**
    *   Analog signal transitions exhibit non-zero rise and fall times, creating unstable voltage intermediate phases.
    *   **Cycle Length Constraint:** The system clock period TT must be engineered to exceed the maximum total internal propagation delay plus computation delay of any sub-circuit:

Tclock cycle>tpd,max+tcomputation, maxT_{\text{clock cycle}} > t_{pd, \text{max}} + t_{\text{computation, max}}

    *   State changes are sampled exclusively at discrete integer transitions (t→t+1t \rightarrow t+1), completely isolating internal intermediate propagation noise (represented inside gray cycle start windows).

Clock Cycle Neutralizing Propagation Delay

*   **Chip Diagram Symbolism:** Clock input signals are explicitly denoted on functional block diagrams by a small triangle icon (Δ\Delta) on the chip boundary.

Fundamental Sequential Building Blocks

  • Data Flip-Flop (DFF):
    • Definition: The foundational 1-bit bistable physical memory element that outputs the input received during its previous clock cycle.
    • Functional Equation:

out(t)=in(t−1)\text{out}(t) = \text{in}(t-1)

*   **Classification of Flip-Flop Types:**
    *   Set-Reset (`SR`) Flip-Flop
    *   Data/Delay (`D`) Flip-Flop
    *   `JK` Flip-Flop
    *   Toggle (`T`) Flip-Flop
*   **Native Implementation:** Primitive `DFF` gates are built physically using cross-coupled `NAND` or `NOR` logic gate latches, but serve as built-in primitive building blocks for higher-level HDL construction.
  • 1-Bit Register (Bit Chip):
    • Motivation: A standard DFF unconditionally overwrites its state at every clock tick. A true register must retain its internal bit indefinitely across time steps until explicitly commanded to store a new bit.
    • Internal Circuit Construction: Formed by combining a DFF with a 2-to-1 Multiplexer (Mux) and a dedicated load control line.
      • Mux Input aa (00 selection line): Connected to the feedback line originating directly from the DFF output line (out), representing state persistence.
      • Mux Input bb (11 selection line): Connected to the external data input pin (in), representing new state load.
      • Mux Selector Signal: Connected directly to the load control signal.
    • Formal Behavioral Specification:

if load(t−1)==1 then out(t)=in(t−1) else out(t)=out(t−1)\text{if } \text{load}(t-1) == 1 \text{ then } \text{out}(t) = \text{in}(t-1) \text{ else } \text{out}(t) = \text{out}(t-1)

*   **State Transition Table / Logic:**

out(t+1)={in(t)if load(t)=1out(t)if load(t)=0\text{out}(t+1) = \begin{cases} \text{in}(t) & \text{if } \text{load}(t) = 1 \\ \text{out}(t) & \text{if } \text{load}(t) = 0 \end{cases}

  • General Sequential Logic Architecture Paradigm:
    • Complex sequential systems consist of an array of clocked state elements (DFF banks) combined with pure combinational logic blocks configured in a continuous state-feedback topology.

Generic Sequential Circuit Block Diagram

Multi-Bit Registers and Memory Architectures

  • Multi-Bit Register Architecture (ww-bit Register):

    • Definition: An array of ww individual 1-bit Bit chips connected in parallel sharing a single unified load signal line.
    • Standard Word Width (ww): Typically w=16w = 16, 3232, or 6464 bits. (The Hack platform specifies w=16w = 16).
    • Functional Interface:
      • in[w]: ww-bit data input line.
      • load: 1-bit write-enable signal line.
      • out[w]: ww-bit stored state output line.
    • Operational Protocol:
      • Read Operation: Continuously probe out bus; output emits stored internal state instantly.
      • Write Operation: Apply value vv to input bus in, assert load = 1. On the next rising clock edge (t+1t+1), internal state transitions to vv, and out emits vv.
  • Memory Hierarchy Abstraction:

    • DFF →\rightarrow Bit (1-bit Register) →\rightarrow ww-bit Register →\rightarrow RAM8 →\rightarrow RAM64 →\rightarrow RAM512 →\rightarrow RAM4K →\rightarrow RAM16K.

Sequential Memory Hierarchy

  • Random Access Memory (RAM) Systems:
    • Definition: A contiguous sequential sequence of nn addressable, ww-bit registers where any individual register location can be accessed directly in constant time (O(1)O(1)).
    • Address Line Calculation: The required address bus width kk for an nn-register RAM module is:

k=log⁡2(n)k = \log_2(n)

*   **Why "Random Access"?** The access delay time taccesst_{\text{access}} to read or write any memory address i∈[0,n−1]i \in [0, n-1] is completely identical and constant, independent of physical geometric position ii relative to index 00.
  • Direct Access Switching Logic:
    • Write Decoding (Demux Routing): A 11-to-nn Demultiplexer (DMux) takes the master load input pin and routes it exclusively to the target register ii matching the provided kk-bit address binary vector. All unselected registers receive load = 0.
    • Read Multiplexing (Mux Selection): An nn-to-11 Multiplexer (Mux) takes the ww-bit output buses of all nn registers, outputting exclusively the output bus of register ii dictated by the kk-bit address input line.

Recursive Structural Build of RAM Chips

  • The Hack 16-Bit RAM Family:

    • RAM8: n=8n = 8 registers, w=16w = 16 bits, k=3k = 3 address bits.
    • RAM64: n=64n = 64 registers, w=16w = 16 bits, k=6k = 6 address bits (composed of 88 RAM8 chips).
    • RAM512: n=512n = 512 registers, w=16w = 16 bits, k=9k = 9 address bits (composed of 88 RAM64 chips).
    • RAM4K: n=4096n = 4096 registers, w=16w = 16 bits, k=12k = 12 address bits (composed of 88 RAM512 chips).
    • RAM16K: n=16384n = 16384 registers, w=16w = 16 bits, k=14k = 14 address bits (composed of 88 RAM4K chips).
  • Recursive Addressing Scheme:

    • To address an nn-register RAM block built from 88 sub-RAM blocks, split the kk-bit address input field into two distinct sub-fields:
      1. High-order 3 bits (address[k-3..k-1]): Fed to a 3-bit DMux8Way and Mux8Way16 to select the exact sub-RAM bank.
      2. Low-order k−3k-3 bits (address[0..k-4]): Routed directly to all 88 sub-RAM blocks simultaneously to select the exact internal register index inside that bank.

Program Counter (PC) Design

  • Role in Computer Architecture: A dedicated ww-bit register situated inside the CPU that maintains the physical memory address of the next machine code instruction scheduled for fetch and execution.

  • Core Abstractions Supported:

    1. Reset: Set counter output to address zero (Fetch initial program boot instruction): PC=0\text{PC} = 0
    2. Next / Increment: Increment internal counter state by one integer step (Sequential execution): PC=PC+1\text{PC} = \text{PC} + 1
    3. Goto / Load: Overwrite counter state with external address input nn (Unconditional/Conditional Jump execution): PC=n\text{PC} = n
    4. Hold State: Retain present memory instruction pointer value: PC=PC\text{PC} = \text{PC}
  • Strict Control Line Priority Order:

reset>load>inc\text{reset} > \text{load} > \text{inc}

  • Formal Control Logic Specification:
if reset(t) then out(t+1) = 0
else if load(t) then out(t+1) = in(t)
else if inc(t) then out(t+1) = out(t) + 1
else out(t+1) = out(t)
  • Implementation Strategy: Constructed internally using a standard 16-bit Register, a 16-bit Combinational Incrementer (Inc16), and three cascaded 16-bit Multiplexers (Mux16) structured sequentially to enforce control signal priority.

Standard Data Measurement Units

  • Data Units Reference Specifications:
UnitAbbreviationDecimal ValueBinary ValueDecimal Size
Bitb00 or 1100 or 1118\frac{1}{8} of a byte
ByteB88 bits88 bits11 byte
KilobyteKB1,00011,000^1 bytes1,02411,024^1 bytes1,0001,000 bytes
MegabyteMB1,00021,000^2 bytes1,02421,024^2 bytes1,000,0001,000,000 bytes
GigabyteGB1,00031,000^3 bytes1,02431,024^3 bytes1,000,000,0001,000,000,000 bytes
TerabyteTB1,00041,000^4 bytes1,02441,024^4 bytes1,000,000,000,0001,000,000,000,000 bytes
PetabytePB1,00051,000^5 bytes1,02451,024^5 bytes1,000,000,000,000,0001,000,000,000,000,000 bytes
ExabyteEB1,00061,000^6 bytes1,02461,024^6 bytes1,000,000,000,000,000,0001,000,000,000,000,000,000 bytes
ZettabyteZB1,00071,000^7 bytes1,02471,024^7 bytes1,000,000,000,000,000,000,0001,000,000,000,000,000,000,000 bytes
YottabyteYB1,00081,000^8 bytes1,02481,024^8 bytes1,000,000,000,000,000,000,000,0001,000,000,000,000,000,000,000,000 bytes

Project 3 Hardware Construction Guidelines

  • Available Primitives:

    • All combinational chips developed in Project 1 and Project 2.
    • Built-in Data Flip-Flop (DFF) primitive.
  • Required Target Hardware Specifications:

    • Bit.hdl (1-bit Register)
    • Register.hdl (16-bit Register)
    • PC.hdl (16-bit Program Counter)
    • RAM8.hdl (8-register 16-bit RAM)
    • RAM64.hdl (64-register 16-bit RAM)
    • RAM512.hdl (512-register 16-bit RAM)
    • RAM4K.hdl (4096-register 16-bit RAM)
    • RAM16K.hdl (16384-register 16-bit RAM)
  • Directory Structure Organization:

    • Sub-folder projects/03/a: Contains Bit, Register, PC, and RAM8 files.
    • Sub-folder projects/03/b: Contains RAM64, RAM512, RAM4K, and RAM16K files.
  • HDL Optimization & Simulation Rules:

    • Follow strict top-down dependency sequence when constructing files.
    • Minimize total gate/component count per chip for maximum throughput efficiency.
    • For simulation execution and consistency, call the system built-in versions of previously created lower-level chips rather than custom HDL sub-files.

Complete Hack Chip Set API Specifications

  • Add16(a= , b= , out= )
  • ALU(x= , y= , zx= , nx= , zy= , ny= , f= , no= , out= , zr= , ng= )
  • And16(a= , b= , out= )
  • And(a= , b= , out= )
  • Aregister(in= , load= , out= )
  • Bit(in= , load= , out= )
  • DFF(in= , out= )
  • DMux4Way(in= , sel= , a= , b= , c= , d= )
  • DMux8Way(in= , sel= , a= , b= , c= , d= , e= , f= , g= , h= )
  • DMux(in= , sel= , a= , b= )
  • Dregister(in= , load= , out= )
  • FullAdder(a= , b= , c= , sum= , carry= )
  • HalfAdder(a= , b= , sum= , carry= )
  • Inc16(in= , out= )
  • Keyboard(out= )
  • Memory(in= , load= , address= , out= )
  • Mux16(a= , b= , sel= , out= )
  • Mux4Way16(a= , b= , c= , d= , sel= , out= )
  • Mux8Way16(a= , b= , c= , d= , e= , f= , g= , h= , sel= , out= )
  • Mux8Way(a= , b= , c= , d= , e= , f= , g= , h= , sel= , out= )
  • Mux(a= , b= , sel= , out= )
  • Nand(a= , b= , out= )
  • Not16(in= , out= )
  • Not(in= , out= )
  • Or16(a= , b= , out= )
  • Or8Way(in= , out= )
  • Or(a= , b= , out= )
  • PC(in= , load= , inc= , reset= , out= )
  • PCLoadLogic(cinstr= , j1= , j2= , j3= , load= , inc= )
  • RAM16K(in= , load= , address= , out= )
  • RAM4K(in= , load= , address= , out= )
  • RAM512(in= , load= , address= , out= )
  • RAM64(in= , load= , address= , out= )
  • RAM8(in= , load= , address= , out= )
  • Register(in= , load= , out= )
  • ROM32K(address= , out= )
  • Screen(in= , load= , address= , out= )
  • Xor(a= , b= , out= )
  • CPU(inM= , instruction= , reset= , outM= , writeM= , addressM= , pc= )