LoginSignup
3
1

More than 5 years have passed since last update.

Packed構造体の表示

Posted at

忘れていたのでメモ。

Packedな構造体のメンバの値をシミュレーション中に1回で表示させるのにPretty Printという機能がある。
「%p」で指定する。

`timescale 1ns/1ps

typedef struct packed {
    logic [7:0] r;
    logic [7:0] g;
    logic [7:0] b;
} rgb_t;

module tb();
    rgb_t rgb;

    initial begin
        for(int i=0; i<10; i++) begin
            rgb.r = $random();
            rgb.g = $random();
            rgb.b = $random();
            $display("%p", rgb);
        end
        $finish(1);
    end

endmodule

結果はこんな感じ。

'{r:'h24, g:'h81, b:'h9}
'{r:'h63, g:'hd, b:'h8d}
'{r:'h65, g:'h12, b:'h1}
'{r:'hd, g:'h76, b:'h3d}
'{r:'hed, g:'h8c, b:'hf9}
'{r:'hc6, g:'hc5, b:'haa}
'{r:'he5, g:'h77, b:'h12}
'{r:'h8f, g:'hf2, b:'hce}
'{r:'he8, g:'hc5, b:'h5c}
'{r:'hbd, g:'h2d, b:'h65}

16進か2進表示しかできないけど、個人的にはあまり問題にしていない。

3
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1