|
|
1 `timescale 1ns/100ps
2 // Type define a struct
3 typedef struct {
4 byte a;
5 reg b;
6 shortint unsigned c;
7 } myStruct;
8
9 module struct_literals ();
10
11 myStruct object = '{10,0,100};
12
13 myStruct objectArray [0:1] = '{'{10,0,100},'{11,1,101}};
14
15 initial begin
16 $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
17 object.a = 15;
18 $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
19 object.c = 16'hDEAD;
20 $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
21 $display ("Printing array of objects");
22 $display ("a = %b b = %b c = %h",
23 objectArray[0].a, objectArray[0].b, objectArray[0].c);
24 $display ("a = %b b = %b c = %h",
25 objectArray[1].a, objectArray[1].b, objectArray[1].c);
26 #1 $finish;
27 end
28
29 endmodule
You could download file struct_literals.sv here
|