Lecture 8 | Sequential Logic

Sequential Logic

How can a circuit remember?

Sequential Logic

What Is Missing from Our Computer?

So far

Every chip we built computes from its current inputs: gates, adders, and the ALU.

But computers must remember

A running program needs stored values, memory locations, and the address of the next instruction.

Definition

State is information retained from an earlier time.

Clock and Time

Representing Time with a Clock

Clock signal and cycles
ticktockticktockticktock cycle 1cycle 2cycle 3 commitcommitcommit
Clock vocabulary
Clock
A signal broadcast to all sequential chips so they agree on time.
Tick and tock
The two phases of the clock signal.
Cycle
One complete tick-tock interval; we treat it as one discrete time unit.
Commit
Stored outputs update only at cycle boundaries.
Clock and Time

What Happens During a Cycle?

Clock cycle example showing a NOT gate and how input and output values change across cycles
Clock cycles make us say exactly when an input is sampled and when an output is observed.
Reading the figure
During a cycle
Combinational logic reacts to the input values it currently receives.
At a boundary
Sequential chips commit their stored outputs.
Why it matters
Without clock cycles, phrases like "previous input" and "next output" are ambiguous.
Data Flip-Flop

Data Flip-Flop (DFF)

A Data Flip-Flop (DFF) is the primitive one-bit time delay used by the simulator.

Specification
Chip name:
DFF
Inputs:
in
Outputs:
out
Function:
out(t)=in(t-1)
Implementation:
Primitive, supplied by the simulator.
DFF symbol
Symbol
DFF timing diagram showing output as the previous cycle input
The output follows the previous cycle's input.
Sequential Logic

Combinational Logic and Sequential Logic

Book figure comparing combinational and sequential chip structure
A sequential chip contains DFF gates, possibly surrounded by combinational logic.
Combinational chipout = f(in)

Output depends only on current input values.

Sequential chipout(t) = f(in(t-1), out(t-1))

Output can depend on earlier input values and earlier stored state.

Next: understand why feedback needs a time delay.

Data Flip-Flop

Why Feedback Needs Time

Next: define the one-bit storage cell we want to build.

Registers

What Is a One-Bit Register?

A one-bit register is a storage cell that remembers one bit until we explicitly load a new bit.

Required behavior
Read
The output continuously shows the currently stored bit.
Hold
If load=0, keep the stored bit even if in changes.
Load
If load=1, store the input bit at the next clock boundary.
Bit chip symbol
Symbol
Terminology

The Hack platform calls this one-bit register chip Bit.

Register

Building a One-Bit Register: First Try

Invalid design with DFF output connected directly back to its input
Invalid design: direct DFF feedback
  • It is not clear how we will ever load this device with a new data value.
  • There is no means to tell the DFF when to draw its input from in and when from out.
  • Internal pins must have fan-in 1: each internal pin must be fed from a single source only.
Register

Correct Implementation of a One-Bit Register

One-bit register built from a Mux and a DFF
Bit = Mux + DFF + feedback
  • Introduce a multiplexor to resolve the input ambiguity.
  • The Mux select bit becomes the register's load bit.
  • If load=1, the register starts storing the new value on in.
  • If load=0, the register keeps storing its internal value.
Registers

The Bit Contract

Specification
Chip name:
Bit (1-bit register)
Inputs:
in, load
Outputs:
out
Function:
If load(t-1) then out(t)=in(t-1); else out(t)=out(t-1).
Read

Probe out. This does not require load=1.

Write

Put the new bit on in and set load=1. The value appears next cycle.

Bit chip symbol
Symbol
Exercise 1

Trace a Bit

Use the Bit behavior: load=1 loads at the next boundary; load=0 holds the old value. Assume the stored bit starts as 0.

Bit chip symbol
Bit symbol
Cycleinloadout after cycle
1100
2111
3001
4010
5100
Exercise 2

Construct the Bit Chip

1

Draw the Mux-DFF feedback circuit.

2

Label in, load, out, and the feedback wire.

3

What goes wrong if the two Mux data inputs are exchanged?

PARTS:
  Mux(a=old, b=in, sel=load, out=next);
  DFF(in=next, out=old, out=out);

The DFF output is used both as the feedback wire and as the chip output.

Registers

From One Bit to a Word

A register stores a multi-bit value. A stored multi-bit value is often called a word.

Bit0
Bit1
Bit2
...
Bit15

All sixteen Bit chips share the same load signal, so all sixteen bits load together.

Registers

The Register Contract

Specification
Chip name:
Register
Inputs:
in[16], load
Outputs:
out[16]
Function:
If load(t-1) then out(t)=in(t-1); else out(t)=out(t-1).
Comment:
The assignment is a 16-bit operation.
Example
cyclein[16]loadout after cycle
10000...001110000...0011
21111...111100000...0011
31111...111111111...1111
Register chip symbol
Symbol
Exercise 3

Exit Questions

1

A Register stores 0000...0111. During a cycle, in=1111...1111 and load=0. What is out after the cycle?

2

The same Register now has load=1. When does the new input become visible at out?

3

If a Register is built from Bit chips, what signal must be shared by all sixteen Bits?

1: 0000...0111; it holds the old word.

2: At the next clock boundary, not immediately.

3: The common load signal.

Next lecture: arrange many Registers as random-access memory.

Next Lecture | Memory

Lecture 9: Random Access Memory

Selecting one word among many using addresses and direct-access logic.