3.5.1 · D3HDL & Digital Design Flow

Worked examples — Verilog - VHDL syntax basics

3,357 words15 min readBack to topic

Before anything, one convention we will reuse everywhere. A bit is one physical wire that is either (low voltage) or (high voltage). A register (flip-flop) is a tiny box that holds one bit and only changes its held value at the instant the clock rises. We draw a clock as a square wave; the moment it goes from up to is the rising edge (posedge clk in Verilog, rising_edge(clk) in VHDL). That instant is the only time a clocked register updates.

Figure — Verilog - VHDL syntax basics

The scenario matrix

Every worked example below is tagged with the cell it covers. The matrix lists every kind of situation the assignment operators can produce.

Cell Situation class What could go wrong
A Pure combinational, assign order-independence, re-evaluation on any input change
B Combinational inside always @(*) with = must assign every path, else latch
C Clocked <=, single register basic edge-triggered store
D Clocked <=, mutual reference (swap/shift) old-value-vs-new-value: the reason <= exists
E Clocked with = (the WRONG operator) collapses N registers into 1: shift-register bug
F Degenerate / zero input, missing branch inferred latch, unknown x
G Bit-width & literal edge cases truncation, zero-extension, signed vs unsigned
H Real-world word problem full FSM-flavoured design
I Exam twist (blocking ordering trap) reading = results mid-block

We now cover every cell.


Cell A — pure combinational assign


Cell B — combinational inside always @(*), complete branches


Cell C — one clocked register with <=

Figure — Verilog - VHDL syntax basics

Cell D — the swap: WHY <= exists

Figure — Verilog - VHDL syntax basics
Figure — Verilog - VHDL syntax basics

Cell E — the shift-register bug (wrong operator)


Cell F — degenerate input: the inferred latch


Cell G — bit-widths, literals, truncation, signed vs unsigned


Cell H — real-world word problem: a rising-edge counter

Figure — Verilog - VHDL syntax basics

Cell I — exam twist: blocking order inside @(*)


Recall Which cell was which? (quiz yourself)

Order-independent assign gates ::: Cell A Complete @(*) mux with default ::: Cell B Basic D-FF with <= ::: Cell C Correct swap needs <= ::: Cell D Wrong = collapses the swap ::: Cell E Missing else → inferred latch ::: Cell F Width truncation, zero- vs sign-extension ::: Cell G Wrapping counter word problem ::: Cell H Blocking chain sees new values ::: Cell I VHDL analogue of Verilog non-blocking <= ::: a signal assignment <= VHDL analogue of Verilog blocking = ::: a variable assignment :=


Connections

  • Combinational vs Sequential Logic — Cells A/B are combinational; C–E, H sequential.
  • Flip-Flops and Latches — Cell C builds a flip-flop; Cell F accidentally builds a latch.
  • Synthesis vs Simulation — Cell E is the canonical mismatch.
  • Finite State Machines in HDL — Cell H is a one-state FSM seed.
  • Number Systems and Bit-Widths — Cells G & H rely on width/wrap and sign arithmetic.
  • Testbenches — where you'd stimulate these edges to reproduce every trace above.