typedef struct {
  bit  [3:0] dst_addr;
  bit  [3:0] src_addr;
  bit [31:0] data;
  bit  [7:0] crc;
} pkt_s;

module test;
  pkt_s pkt1;

  initial begin
    init('{4'h9, 4'h6, 32'h1234ABCD, 8'h00});
    pkt1.crc = gen_crc(pkt1.data);
    show_pkt;
    $finish;
  end

  function void init (pkt_s d);
    pkt1 = d;
  endfunction

  function [7:0] gen_crc (int d);
    for (int i=0;i<8;i++) gen_crc[i]=^d[(i*4)+:4];
  endfunction

  function void show_pkt;
    $display("dst=%h src=%h data=%h crc=%h", 
	     pkt1.dst_addr, pkt1.src_addr, pkt1.data, pkt1.crc); 
  endfunction
endmodule
