How HDL Differs From Software: Concurrency, Wires and Registers
A hardware description language describes circuits that all run at once, not steps. See how concurrency, wires and registers change how you read Verilog.

A firmware engineer who opens a Verilog file for the first time sees if, case, for and =, and reasonably assumes that a program is running. It is not. A hardware description language, or HDL, describes a circuit, and a circuit has no program counter. This post explains the three ideas that separate HDL from software: everything runs at once, wires and registers are different things, and a loop is a copy of hardware rather than a repeat in time. The examples are Verilog as defined by IEEE 1364-2005 and simulate under Icarus Verilog 12.0.
Everything is always running
In C, two statements run one after the other. The second can read what the first wrote because the processor finished the first before starting the second. In Verilog, a module is a set of hardware blocks that are all active from the moment power is applied. Take two continuous assignments:
module concurrent (
input wire a,
input wire b,
output wire sum_bit,
output wire carry
);
assign sum_bit = a ^ b;
assign carry = a & b;
endmoduleThis is a half adder. The XOR gate and the AND gate both exist, both watch a and b, and both update whenever either input changes. If you swapped the two lines the circuit would be identical. Order in the file carries no meaning for this kind of code, which is the first thing to unlearn.
The simulator is a program, so internally it does run one thing after another. But it models time and schedules events so that the result looks like parallel hardware. The language standard defines that scheduling precisely, and a design that gives different answers depending on the simulator's internal order is considered buggy.
What "always" really means
An always block is not a function that gets called. It is a piece of hardware with a sensitivity list that says when its behaviour is re-evaluated. always @(posedge clk) describes logic that captures its inputs at each rising clock edge. always @* describes logic that tracks its inputs continuously. Both blocks exist at all times, and a module with ten of them has ten active pieces of hardware.
A wire is a connection, a register is a memory
Software has variables. Hardware has two different things that a software reader tends to merge.
A wire carries a value from a driver to the places that read it. It stores nothing. If the driver changes, the wire changes with it, after the propagation delay of the gates in between. In Verilog the keyword is wire, and it is driven by assign or by a module's output port.
A register holds a value across time. The standard building block is a D flip-flop: on each active clock edge it copies its input to its output, and keeps that output until the next edge. In Verilog, a register is a reg assigned in a clocked always block.
The name reg causes trouble, because Verilog uses it for anything assigned inside an always block, including logic that is purely combinational. In that case, no storage is built, and the keyword only reflects the way the signal is assigned. The test for whether you built memory is not the keyword. It is whether the value must be remembered between clock edges.
module reg_vs_wire (
input wire clk,
input wire [3:0] a,
input wire [3:0] b,
output wire [3:0] sum_now,
output reg [3:0] sum_held
);
assign sum_now = a + b;
always @(posedge clk)
sum_held <= a + b;
endmodulesum_now follows a + b all the time. sum_held captures the sum on each rising edge and holds it until the next. Both use the same adder logic. The difference is a bank of four flip-flops after it.
Here is a small simulation to see the difference in time:
`timescale 1ns/1ps
module reg_vs_wire_tb;
reg clk = 1'b0;
reg [3:0] a = 4'd1;
reg [3:0] b = 4'd2;
wire [3:0] sum_now;
wire [3:0] sum_held;
reg_vs_wire dut (.clk(clk), .a(a), .b(b), .sum_now(sum_now), .sum_held(sum_held));
always #5 clk = ~clk;
initial begin
#1 $display("t=%0t now=%0d held=%b", $time, sum_now, sum_held);
#5 $display("t=%0t now=%0d held=%0d", $time, sum_now, sum_held);
a = 4'd5;
#1 $display("t=%0t now=%0d held=%0d", $time, sum_now, sum_held);
#10 $display("t=%0t now=%0d held=%0d", $time, sum_now, sum_held);
$finish;
end
endmodulet=1000 now=3 held=xxxx
t=6000 now=3 held=3
t=7000 now=7 held=3
t=17000 now=7 held=7Times print in picoseconds because the timescale precision is 1 ps. Before the first clock edge at 5 ns, sum_held is unknown, shown as xxxx, because nothing has loaded it yet. After the edge, it holds 3. When a changes at 6 ns, sum_now follows immediately and shows 7, but sum_held still shows 3 until the next edge at 15 ns. That delay between the combinational answer and the registered one is the central rhythm of synchronous design.
Loops are copies of hardware
A for loop in synthesisable Verilog does not repeat over time. The tool unrolls it at build time into parallel hardware. Here is a population count, which counts the set bits of a byte:
module popcount (
input wire [7:0] v,
output reg [3:0] n
);
integer i;
always @* begin
n = 4'd0;
for (i = 0; i < 8; i = i + 1)
n = n + v[i];
end
endmoduleThe loop does not iterate eight times in sequence. The synthesis tool builds a tree of adders, one stage per loop step, all present at once, and the answer appears after the combined delay of that chain. If you wanted to take eight clock cycles to count the bits, you would write a state machine with a counter, and that would be a different circuit with a different cost. This is the key trade in hardware design: spend area to go fast, or spend time to stay small.
Time exists in two different forms
Software has one kind of time, the order in which statements run. Hardware has two.
Simulation time is the clock of the simulator. It lets you say #10 to wait ten time units, which is useful in a testbench and meaningless in a real chip, because gates cannot be told to wait.
Clock cycles are the time that real hardware has. A design does one thing per cycle per piece of logic, and to take longer you add more cycles, usually with a counter or a state machine.
Mixing these up is a common beginner mistake. Writing #100 in a design file does nothing in synthesis, and the simulation then disagrees with the built hardware.
What this changes in how you read code
The following habits help when you move from software to HDL.
Read an
always @(posedge clk)block as "what each flip-flop loads at the next edge", not as "what happens in order".Read
assignandalways @*as "what this wire equals", an equation that is always true.Count the registers. Every
regthat is assigned in a clocked block costs flip-flops equal to its width, and a design's size is mostly registers plus the logic between them.Ask what happens in one clock cycle. If a computation needs more than one cycle of logic delay, split it with a register.
Treat a variable that must keep its value as a register you must create on purpose, and a variable that should not keep a value as a signal you must assign on every path.
Where the comparison breaks down
The software analogy is useful for syntax and misleading for behaviour, and it fails in a few places worth naming. A software function can recurse. Synthesisable hardware cannot, because recursion would need unbounded hardware. A software program shares one processor among many tasks. Hardware gives each task its own circuit unless you build a scheduler, so parallel work is cheap and sequential sharing costs design effort. Software memory is large and uniform. Hardware memory is a mix of flip-flops, small block RAMs and external chips, each with its own timing. Treat those as architecture decisions, not language details.


