EC 5110 Logic Synthesis and Verification Lecture Notes 10102024
EC 5110 Logic Synthesis and Verification Lecture Notes 10102024
module BlockingAssignmentExample2;
reg [7:0] a, b, c, d, e; Output
initial begin
a = 8'hDA;
$display ("[%0t] a=0x%0h b=0x%0h c=0x%0h", $time, a, b, c); [0] a=0xda b=0xx c=0xx
#10 b = 8'hF1;
$display ("[%0t] a=0x%0h b=0x%0h c=0x%0h", $time, a, b, c); [5] d=0xaa e=0xx
c = 8'h30;
$display ("[%0t] a=0x%0h b=0x%0h c=0x%0h", $time, a, b, c); [10] a=0xda b=0xf1 c=0xx
end
[10] a=0xda b=0xf1 c=0x30
initial begin
#5 d = 8'hAA; [10] d=0xaa e=0x55
$display ("[%0t] d=0x%0h e=0x%0h", $time, d, e);
#5 e = 8'h55;
$display ("[%0t] d=0x%0h e=0x%0h", $time, d, e);
end
endmodule
initial
begin: seq_blk_a # procedural blocks can be assigned labels
integer index;
speed_reg = 0;
always
wait (set == 1)
begin
#3 q <= 1; # will discuss <= when we get to
#2 qbar <= 0; # non‐blocking assignment
wait (set == 0);
end
…
…
Explanation
• A read operation is performed on each RHS variable in1, in2, in3, and reg1 at the posedge of clock
• All the RHS expressions are evaluated, and stored internally.
• Write operations to the LHS are scheduled to be executed at the time specified by the intra‐assign
statement, ie. write to reg1 after 1 time unit, to reg2 at the next negative edge of clock, and to reg3
after 1 time unit
• The order in which the write operations are performed is irrelevant as the values are already stored
Explanation
• In the first case, it will take 3 clock cycles for the value of 1 to propagate to r_test_3.
• In the second case the value of 1 will propagate to r_test_3 in the first clock cycle itself
In Verilog, if you want to create sequential logic use a clocked always block with Nonblocking
assignments. If you want to create combinational logic use an always block with Blocking
assignments. Try not to mix the two in the same always block.
endmodule
Before the simulation, the simulator elaborates (expands) the code to create a flat representation
genvar is a keyword used to declare variables that are used only in the evaluation of the generate block
The value of genvar can be defined only by a generate loop
Generate loops can be nested but only if the nested loops do not use the same genvar as an index
Generate can be used for conditional statements including case.
integer result;
initial
begin
result = factorial(4)
$display(“Factorial of 4 is %0d”, result)
end
endmodule
Can contain delay, event, or timing control Cannot contain any delay, event, or timing
statements control statements
May have zero or more arguments of type Must have one or more input arguments
input, output, or inout
Do not return any value, but can pass multiple Always return a single value. Cannot have
values through output, and inout arguments output or inout arguments