`timescale 1ns/1ns
module tb;
logic [3:0] a, b;
logic [4:0] c;
initial begin
//---time slot 0ns---
a = 4'h7;
b = 4'hA;
// Active region, blocking assignment for a and b.
$display("PRT %0t ns: a = %0h, b = %0h, c = %0h", $time, a, b, c);
// Active region, $display.
// Postponed region, $monitor due to blocking assignment of a and b.
//------------------
//---time slot 5ns---
#5;
c <= a + b;
// Active region, evaluate RHS of NBA c.
$display("PRT %0t ns: a = %0h, b = %0h, c = %0h", $time, a, b, c);
// Active region, $display.
// NBA region, update LHS of NBA c.
// Postponed region, $monitor due to LHS updates of c.
//------------------
//---time slot 8ns---
#3;
a = 4'h3;
b = 4'hB;
c = a + b;
// Active region, blocking assignment for a, b and c.
$display("PRT %0t ns: a = %0h, b = %0h, c = %0h", $time, a, b, c);
// Active region, $display.
// Postponed region, $monitor due to blocking assignment of a, b and c.
//------------------
//---time slot 10ns---
#2;
a = 4'h5;
b = 4'h5;
c <= a + b;
// Active region, blocking assignment for a and b / evaluate RHS of NBA c.
$display("PRT %0t ns: a = %0h, b = %0h, c = %0h", $time, a, b, c);
// Active region, $display.
// NBA region, update LHS of NBA c.
// Postponed region, $monitor due to LHS updates of c.
//------------------
//---time slot 15ns---
#5;
a <= 4'hC;
b <= 4'h8;
c <= a;
// Active region, evaluate RHS of NBA a, b and c.
$display("PRT %0t ns: a = %0h, b = %0h, c = %0h", $time, a, b, c);
// Active region, $display.
// NBA region, update LHS of NBA c based on value of a in previous time slot.
// NBA region, update LHS of NBA a and b.
// Postponed region, $monitor
//------------------
//---time slot 20ns---
#5;
a = 4'h0;
b = 4'h2;
// Active region, blocking assignment for a and b.
#0 a = 4'h1;
// inactive region, #0 blocking assignment for a.
c = a + b;
// Active region, blocking assignment for c.
$display("PRT %0t ns: a = %0h, b = %0h, c = %0h", $time, a, b, c);
// Active region, $display.
// Postponed region, $monitor
//------------------
end
initial begin
$monitor("MON %0t ns: a = %0h, b = %0h, c = %0h", $time, a, b, c);
end
endmodule
运行结果:
PRT 0 ns: a = 7, b = a, c = xx
MON 0 ns: a = 7, b = a, c = xx
PRT 5 ns: a = 7, b = a, c = xx
MON 5 ns: a = 7, b = a, c = 11
PRT 8 ns: a = 3, b = b, c = e
MON 8 ns: a = 3, b = b, c = e
PRT 10 ns: a = 5, b = 5, c = e
MON 10 ns: a = 5, b = 5, c = a
PRT 15 ns: a = 5, b = 5, c = a
MON 15 ns: a = c, b = 8, c = 5
PRT 20 ns: a = 1, b = 2, c = 3
MON 20 ns: a = 1, b = 2, c = 3