Quick reference for the educational simulator — one synthesizable module per design.
module name ( /* ANSI ports */ );
// net / variable declarations
// assign, always_comb, always_ff
endmodule
Only the first module in the file is parsed.
module add (
input logic [7:0] a, b,
input logic signed [3:0] d,
output wire [8:0] s
);
input, outputlogic / wire / int, optional signed, optional [msb:lsb]logic [3:0] cnt, nxt;
wire carry;
logic signed [7:0] acc;
A declaration gives a name and an optional width.
assign a = b | c;
assign x[3:0] = y[7:4];
assign {cout, sum} = a + b;
Concatenation targets are also allowed with = and <= in procedural blocks. assign targets need constant indexes.
{a, b[3:0], 2'b01}
{4{bit}} {W{1'b0}}
5) inside {} are errorsN: positive constant expressionalways_comb begin
y = '0;
if (en) y = a;
else y = b;
end
=, if/else, case, forx++ x-- ++x --x, += -= *= &= |= ^= <<= >>=sum = sum + a[i] worksalways_ff @(posedge clk or negedge rst_n)
if (!rst_n) q <= '0;
else q <= d;
<= only; if/else, case, for, begin/endor or ,: the first event is the clock (posedge); further events are asynchronousunique case (sel)
2'd0, 2'd1: y = a;
2'd2: begin y = b; z = 1; end
default: y = '0;
endcase
casez (req) 4'b1???: g = 3; ... endcase
case, casez (?/z = don't care), casex (also x); in always_comb and always_ffif, case, begin…end or ;unique / priority accepted but not checkedtypedef enum logic [1:0]
{IDLE, RUN, DONE = 2'd3} state_t;
state_t state, next;
enum logic {OFF, ON} mode; // anonymous
logic/bit [msb:lsb] or int (default, 32 bits)logic signed [7:0] a; int i;
8'sd5 4'sb1111 $signed(x) $unsigned(x)
int is signed 32-bit< <= > >= compare signed if both sides arelogic [3:0][7:0] w; // 4 bytes = 32-bit vector
w[2] w[2][3:0] w[2][7] w[2:1]
w[i] <= d;
signed, intlogic [7:0] mem [0:255];
logic [7:0] regs [8]; // = [0:7]
logic [7:0] rom [0:3] =
'{8'h11, 8'h22, 8'h33, 8'h44};
y = mem[addr][7:4]; regs[i] <= d;
mem[a:b] slices, 2nd unpacked dimension or whole-array use0-3, 10, 200-203 or all (max 256)int and for loopsalways_comb begin
ones = 0;
for (int i = 0; i < 8; i++)
ones += a[i];
end
int / integer: signed 32-bit (variables, ports, loop variables)int|integer|logic [..] i = e (local) or i = e (existing variable)i++ i-- ++i --i i += e i -= e i = e; max 65 536 iterationsmodule m #(parameter W = 8, N = 4,
localparam M = W * 2) (...);
localparam [7:0] K = 8'hA5;
localparam int N2 = 4, M2 = N2 * 2;
int, logic/bit [signed] [range], signed [range], [range]; untyped takes its value's type (P = 5 → signed 32-bit)'0, '1 (no 'x, 'z)The Testbench button in the wave viewer generates tb_<module>.sv:
#(.W(..)), clock rising at 10t$dumpvars for a VCD$finish after the last cycle| Group | Operators | |
|---|---|---|
| 1 | Primary | identifiers, constants, (e), a[i], a[msb:lsb], {a, b}, {N{a}} |
| 2 | Unary | ~ ! -, reduction & ~& | ~| ^ ~^ ^~, $signed(), $unsigned() |
| 3 | Multiplicative | * (/ % ** not supported) |
| 4 | Additive | + - |
| 5 | Shift | << >> <<< >>> |
| 6 | Relational | < <= > >= |
| 7 | Equality | == != |
| 8 | Bitwise AND | & |
| 9 | Bitwise XOR | ^ ~^ ^~ |
| 10 | Bitwise OR | | |
| 11 | Logical AND | && |
| 12 | Logical OR | || |
| 13 | Conditional | c ? a : b (right-associative) |
generate blocksassign with delaysreg, tri and other net kindsalways, initialwhile, repeat, forever/ % ** operatorsinout, var, array portsbit, byte, shortint… as variable types'x, 'z fill literals; parameter overrides
7Comments & stimulus
A
/* stimulus <cycles> … */block defines input waveforms for the wave viewer.