スポンサーサイト

上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

[SystemVerilog] foreach(配列編)

きっかけはこちらのスレッドです。


To write a simple checker


ここに foreach文の引数に配列を入れた場合のものが記載しています。
というわけで、掲示板に書いてあるサンプルコードを動かしてみました。

  • サンプルコード

  •  1|module testbench ();
     2|
     3|  bit array[10][2:0][3:0];
     4|
     5|  initial begin
     6|    array[0] = '{'{1,1,0,0},'{1,1,1,1},'{0,0,1,1}};
     7|    foreach(array[i,j,k]) begin
     8|      $display("Array[%0d,%0d,%0d] = %0p", i,j,k, array[i][j][k]);
     9|      if(array[i][j][k] != 1) begin
    10|        $display("The element is not 1");
    11|      end
    12|    end
    13|    $finish(1);
    14|  end
    15|
    16|endmodule: testbench
  • 実行結果

# Array[0,2,3] = 1
# Array[0,2,2] = 1
# Array[0,2,1] = 0
# The element is not 1
# Array[0,2,0] = 0
# The element is not 1
# Array[0,1,3] = 1
# Array[0,1,2] = 1
# Array[0,1,1] = 1
# Array[0,1,0] = 1
# Array[0,0,3] = 0
# The element is not 1
# Array[0,0,2] = 0
# The element is not 1
# Array[0,0,1] = 1
# Array[0,0,0] = 1
# Array[1,2,3] = 0
# The element is not 1
# Array[1,2,2] = 0
# The element is not 1
# Array[1,2,1] = 0
# The element is not 1
# Array[1,2,0] = 0
# The element is not 1
# Array[1,1,3] = 0
# The element is not 1
# Array[1,1,2] = 0
# The element is not 1
# Array[1,1,1] = 0
# The element is not 1
# Array[1,1,0] = 0
# The element is not 1
# Array[1,0,3] = 0
# The element is not 1
# Array[1,0,2] = 0
# The element is not 1
# Array[1,0,1] = 0
# The element is not 1
# Array[1,0,0] = 0
# The element is not 1
# Array[2,2,3] = 0
# The element is not 1
# Array[2,2,2] = 0
# The element is not 1
# Array[2,2,1] = 0
# The element is not 1
# Array[2,2,0] = 0
# The element is not 1
# Array[2,1,3] = 0
# The element is not 1
# Array[2,1,2] = 0
# The element is not 1
# Array[2,1,1] = 0
# The element is not 1
# Array[2,1,0] = 0
# The element is not 1
# Array[2,0,3] = 0
# The element is not 1
# Array[2,0,2] = 0
# The element is not 1
# Array[2,0,1] = 0
# The element is not 1
# Array[2,0,0] = 0
# The element is not 1
# Array[3,2,3] = 0
# The element is not 1
# Array[3,2,2] = 0
# The element is not 1
# Array[3,2,1] = 0
# The element is not 1
# Array[3,2,0] = 0
# The element is not 1
# Array[3,1,3] = 0
# The element is not 1
# Array[3,1,2] = 0
# The element is not 1
# Array[3,1,1] = 0
# The element is not 1
# Array[3,1,0] = 0
# The element is not 1
# Array[3,0,3] = 0
# The element is not 1
# Array[3,0,2] = 0
# The element is not 1
# Array[3,0,1] = 0
# The element is not 1
# Array[3,0,0] = 0
# The element is not 1
# Array[4,2,3] = 0
# The element is not 1
# Array[4,2,2] = 0
# The element is not 1
# Array[4,2,1] = 0
# The element is not 1
# Array[4,2,0] = 0
# The element is not 1
# Array[4,1,3] = 0
# The element is not 1
# Array[4,1,2] = 0
# The element is not 1
# Array[4,1,1] = 0
# The element is not 1
# Array[4,1,0] = 0
# The element is not 1
# Array[4,0,3] = 0
# The element is not 1
# Array[4,0,2] = 0
# The element is not 1
# Array[4,0,1] = 0
# The element is not 1
# Array[4,0,0] = 0
# The element is not 1
# Array[5,2,3] = 0
# The element is not 1
# Array[5,2,2] = 0
# The element is not 1
# Array[5,2,1] = 0
# The element is not 1
# Array[5,2,0] = 0
# The element is not 1
# Array[5,1,3] = 0
# The element is not 1
# Array[5,1,2] = 0
# The element is not 1
# Array[5,1,1] = 0
# The element is not 1
# Array[5,1,0] = 0
# The element is not 1
# Array[5,0,3] = 0
# The element is not 1
# Array[5,0,2] = 0
# The element is not 1
# Array[5,0,1] = 0
# The element is not 1
# Array[5,0,0] = 0
# The element is not 1
# Array[6,2,3] = 0
# The element is not 1
# Array[6,2,2] = 0
# The element is not 1
# Array[6,2,1] = 0
# The element is not 1
# Array[6,2,0] = 0
# The element is not 1
# Array[6,1,3] = 0
# The element is not 1
# Array[6,1,2] = 0
# The element is not 1
# Array[6,1,1] = 0
# The element is not 1
# Array[6,1,0] = 0
# The element is not 1
# Array[6,0,3] = 0
# The element is not 1
# Array[6,0,2] = 0
# The element is not 1
# Array[6,0,1] = 0
# The element is not 1
# Array[6,0,0] = 0
# The element is not 1
# Array[7,2,3] = 0
# The element is not 1
# Array[7,2,2] = 0
# The element is not 1
# Array[7,2,1] = 0
# The element is not 1
# Array[7,2,0] = 0
# The element is not 1
# Array[7,1,3] = 0
# The element is not 1
# Array[7,1,2] = 0
# The element is not 1
# Array[7,1,1] = 0
# The element is not 1
# Array[7,1,0] = 0
# The element is not 1
# Array[7,0,3] = 0
# The element is not 1
# Array[7,0,2] = 0
# The element is not 1
# Array[7,0,1] = 0
# The element is not 1
# Array[7,0,0] = 0
# The element is not 1
# Array[8,2,3] = 0
# The element is not 1
# Array[8,2,2] = 0
# The element is not 1
# Array[8,2,1] = 0
# The element is not 1
# Array[8,2,0] = 0
# The element is not 1
# Array[8,1,3] = 0
# The element is not 1
# Array[8,1,2] = 0
# The element is not 1
# Array[8,1,1] = 0
# The element is not 1
# Array[8,1,0] = 0
# The element is not 1
# Array[8,0,3] = 0
# The element is not 1
# Array[8,0,2] = 0
# The element is not 1
# Array[8,0,1] = 0
# The element is not 1
# Array[8,0,0] = 0
# The element is not 1
# Array[9,2,3] = 0
# The element is not 1
# Array[9,2,2] = 0
# The element is not 1
# Array[9,2,1] = 0
# The element is not 1
# Array[9,2,0] = 0
# The element is not 1
# Array[9,1,3] = 0
# The element is not 1
# Array[9,1,2] = 0
# The element is not 1
# Array[9,1,1] = 0
# The element is not 1
# Array[9,1,0] = 0
# The element is not 1
# Array[9,0,3] = 0
# The element is not 1
# Array[9,0,2] = 0
# The element is not 1
# Array[9,0,1] = 0
# The element is not 1
# Array[9,0,0] = 0
# The element is not 1
# ** Note: $finish   
関連記事

コメントの投稿

非公開コメント

プロフィール

Kocha

Author:Kocha
なんでもチャレンジ!(^o^)/
E-mail
github:Kocha
イベントカレンダー

カレンダー
04 | 2017/05 | 06
- 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 - - -
カテゴリ
OVP (4)
最新記事
最新コメント
アーカイブ
リンク
Twitter
アクセス人数
上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。