SV——在Verilog和SV的block中定義局部變量

 

0. 介紹

在Verilog和systemverilog中的begin..end和fork..join block中都可以定義局部變量。但有區別。

 

1. Verilog

Verilog allows local variables to be declared in named begin...end and
fork...join blocks. These variables can be referenced hierarchically, using the
block name as part of the hierarchical path.

module ehip_vlog_style (... );
    always @(posedge elk)
        for (i=O; i<=15; i=i+l) begin: loop
        integer temp;
    end
endmodule

module test;
    II named block
    II local variable
    ehip_vlog_style dut (... );
    initial $display ("temp = %Od", test.dut.loop.temp); II OK
endmodule

 

2. System Verilog

SystemVerilog simplifies Verilog by allowing local variables to be declared in
unnamed begin...end and fork...join blocks.

module ehip_sv_style (... );
    always_ff @(posedge elk)
        for (int i=O; i<=15; i++) begin
        integer temp;
    end
endmodule

program automatic test;
    Verilog and SystemVeriiog Gotchas
    chip_sv_style dut (... );
    initial $display ("temp = %Od", test.dut.temp); II GOTCHA!
endmodule

3. reference

《Verilog and SystemVerilog Gotchas》

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章