10-Verilog Common Reference Guide
10-Verilog Common Reference Guide
Comments
2. Data Types
wire
wire result;
assign result = a & b;
reg
reg result;
always @(posedge clk) begin
result <= a & b;
end
3. Procedural Blocks
Always Block (Sequential Logic)
SEMICON CENTER
always @(posedge clk) begin
out <= a + b;
end
Always # Statement
4. Conditional Statements
If-Else Statement
Case Statement
SEMICON CENTER
5. Blocking vs Non-blocking Assignments
Blocking Assignment (=)
6. Loops in Verilog
For Loop
Generate-For Loop
genvar i;
generate
for (i = 0; i < 8; i = i + 1) begin
assign y[i] = a[i] & b[i];
end
endgenerate
Forever Loop
SEMICON CENTER
7. Timing Controls in Verilog
#delay
Return values and can be used in expressions. Must execute in a single time unit.
Tasks
Can span multiple time units and may not return a value.
task delay_task;
begin
#5;
$display("Task completed");
end
endtask
SEMICON CENTER
Calling Functions and Tasks
Function Call:
y = add(a, b);
Task Call:
9. Parameters
Parameterized Module
Local Parameters
SEMICON CENTER
11. Latches and Race Conditions
Latch Inference
Solution: Ensure all cases are covered with else or default assignments.
Race Conditions
b = a;
SEMICON CENTER
13. Final Summary
SEMICON CENTER
generate Synthesis directive used to replicate generate for (i = 0; i <
8; i = i + 1) assign
hardware structures in a out[i] = in1[i] & in2[i];
parameterized way. endgenerate
SEMICON CENTER
Table 3: Testbench Constructs and Utilities
Syntax Description Example
$monitor Continuously monitors and prints signal $monitor("time=%0t
a=%b", $time, a);
changes throughout simulation
(testbenches).
$display Prints signal values once during $display("a=%b, b=%b",
a, b);
simulation at a specific point.
$finish Ends the simulation. initial $finish;
$stop Pauses simulation for debugging initial $stop;
purposes.
$time Retrieves the current simulation time. $display("Time: %0t",
$time);
disable Terminates a block of code or named disable my_block;
block in a function or task.
primitive Defines a basic gate primitive (AND, OR, primitive my_and(out, a,
b); ... endprimitive
etc.) in Verilog.
defparam Changes the value of a parameter after defparam
my_instance.WIDTH = 16;
module instantiation (not preferred).
always_comb Used to define combinational logic that always_comb out = a & b;
should run anytime any input changes
(SystemVerilog, a stricter version of
always @*).
always_ff Defines sequential logic driven by a always_ff @(posedge clk)
q <= d;
clock edge (SystemVerilog, stricter
version of always @(posedge clk)).
SEMICON CENTER