shtaxxx日記

コンピュータアーキテクチャについて研究している研究者の日記や技術紹介

名前付きブロック (Named Block)の中ならalways文中でもreg宣言ができる

scope0とscope1のそれぞれでreg [7:0] aを宣言

module Test;
    reg [7:0] b;
    always @* begin: scope0
        reg [7:0] a;
        a = b;
        begin: scope1
            reg [7:0] a;
            a = b + 1;
            $display("scope1: a=%d", a);
        end
        $display("scope0: a=%d", a);
    end
    
    initial begin
        b = 10;
        #10;
        b = 20;
        #10;
        $finish;
    end
endmodule

実行結果

scope1: a= 11
scope0: a= 10
scope1: a= 21
scope0: a= 20