SV-- local variables defined in the block in Verilog and SV

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/m0_38037810/article/details/102758440

 

0. Introduction

In the Verilog and systemverilog begin..end fork..join block and local variables can be defined both. But there are differences.

 

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》

 

Guess you like

Origin blog.csdn.net/m0_38037810/article/details/102758440