您将学到什么

  • Store a 4-bit value in a parallel-load register.
  • Recognize a register as parallel D flip-flops sharing a clock.
  • See how every bit captures D on the clock edge synchronously.
  • Connect this to CPU register files and pipeline stages.
  • Understand setup/hold timing across multiple bits.

工作原理

A 4-bit register stores a 4-bit value, updated synchronously on each clock edge. Internally it's four D flip-flops in parallel, all clocked by the same signal. Each clock edge captures the four data inputs (D3..D0) into the four flip-flops; their outputs (Q3..Q0) hold the value until the next clock edge.

A register is the fundamental storage element for multi-bit values in synchronous designs. Every CPU register, every pipeline stage's data, every state machine state register is a parallel D flip-flop bank like this.

With just a clock input, the register loads new data every cycle — equivalent to an unconditional move. To store data only when commanded, add a write-enable input that gates the flip-flop's enable; this is the next template (Register Load Control Demo).

Key timing: setup time (data must be stable before clock edge) and hold time (data must remain stable after clock edge) apply per bit. Worst-case path is the slowest of the four bits, but typically all bits have similar timing.

逐步尝试

在上方嵌入式电路中设置输入,然后阅读预期结果并验证。

  1. 1
    D = 1010 Clock = rising
    预期: Q = 1010
    您将看到: Set inputs to 1010, raise the clock — register captures all 4 bits simultaneously. Output reflects 1010 (= 10).
  2. 2
    D = 0101 Clock = rising again
    预期: Q = 0101
    您将看到: Change inputs to 0101 and clock — new value captured. The previous value is overwritten.
  3. 3
    D = varying Clock = stopped
    预期: Q frozen
    您将看到: Stop the clock — Q holds whatever it was. D's changes have no effect until the next clock edge.
  4. 4
    D = all 0 Clock = rising
    预期: Q = 0000
    您将看到: Clock with D = 0000 → register loads zeros. Effectively a clear-to-zero on every cycle if D is held at 0.

使用的组件

实际应用

CPU register file. Each architectural register (e.g., RAX, R0, x0) is implemented as a clocked register cell like this, organized in a register file with read and write ports.

Pipeline-stage registers. Every pipeline stage in a CPU has registers between it and the next stage; data flows synchronously stage-to-stage on each clock edge.

Data bus interface. External bus signals are sampled into a register before being processed in the CPU's clock domain.

Configuration registers. Memory-mapped peripheral registers store control bits; firmware writes set them via a register-load on the bus-clock edge.

FIFO entries. Each FIFO buffer slot is a register cell, with write-enable selectively triggering one entry's load.

常见问题

What's the difference between a register and a counter?
A register stores a value loaded from D inputs; a counter generates a sequence of values via internal next-state logic. Both use flip-flops; the counter adds combinational logic that computes the next count from the current state.
Can I read and write the register in the same cycle?
Read of Q happens any time (combinational output of the flip-flops). Write happens on the next clock edge. So in one cycle you can read the current Q and present a new D for the next cycle's load.
How does this scale to wider registers?
Just add more flip-flops in parallel. An 8-bit register is 8 DFFs sharing a clock; 64-bit is 64 DFFs. CMOS process can pack hundreds of flip-flops into a small area.
What if some bits' D inputs settle later than others?
Worst-case timing is governed by the slowest input. Synthesis tools route signals to balance arrival times. If one input is consistently late, you can pipeline that path with an extra flip-flop.
Why use a register instead of a latch?
Registers (edge-triggered) are glitch-immune — D can wiggle freely between edges. Latches (level-sensitive) are transparent during clock-high, so glitches propagate. Synchronous designs almost always use registers (flip-flops) over latches.

继续学习