Cheatsheets
Verilog
Modules, wire/reg, blocking vs non-blocking, and always blocks.
Visualize
Digital logic — a clocked timing diagram
Synchronous logic only changes on the rising clock edge; reset forces a known state.
Press play — the cursor sweeps time; q steps on each rising clk edge.
18 entries
Modules & ports5
module counter (
input clk,
input rst_n,
output reg [7:0] q
);
endmoduleComplete 8-bit counter with synchronous reset.
input / output / inoutPort directions
foo u1 (.a(x), .b(y));Instantiate by name
parameter WIDTH = 8;Compile-time parameter
`define MAX 255Preprocessor macro
Data types5
wireContinuous connection (driven by assign / output)
regHolds a value (assigned in always/initial)
[7:0] bus8-bit vector — mind the width on arithmetic.
8'hFF 4'b1010 8'd255Sized hex / binary / decimal literals
logic (SystemVerilog)Unified type replacing wire/reg
Assignments3
assign y = a & b;Continuous (combinational) assignment
<= (non-blocking) vs = (blocking)The #1 Verilog gotcha — pick by block type.
y = sel ? a : b;Ternary mux
Always blocks5
always @(posedge clk) begin
if (rst) q <= 0;
else q <= q + 1;
endSynchronous (sequential) logic — non-blocking.
always @(*) begin
case (sel)
2'b00: y = a;
default: y = b;
endcase
endCombinational logic — blocking, full case.
always @(posedge clk or negedge rst_n)Async reset sensitivity
TestbenchRecipe: drive a clock and observe with $monitor.
initial begin ... endRuns once at t=0 (testbench)