Accessing local module variables from test benches in Verilog

筅森魡賤 提交于 2021-02-07 14:33:26

问题


When writing a Verilog test bench to verify a module is there any way to access a particular variable local to that module from the test bench?


回答1:


Use hierarchical reference to access cross-hierarchical variable.

For accessing variable in the sub-hierarchy of current module, you can use relative path, as in example below, "dut.localvar".

For accessing variable of a module which is not part of current module hierarchy, use absolute path from the top, e.g., "testbench.dut.localvar".

module testbench();
reg clk;
wire out;

DUT dut(clk, out);

always@(posedge clk)
begin
   $display("%b", dut.local_var);
end
endmodule

module DUT(input wire clk,output reg out);
reg local_var = 1'b0;

always@(posedge clk)
begin
   local_var = ~local_var;
end
endmodule


来源:https://stackoverflow.com/questions/19738164/accessing-local-module-variables-from-test-benches-in-verilog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!