|
|
Structure and union declarations types are same as that found in C language. One can use the structure data types to declare complex data type, which is nothing but a collection of other data types. Example would be a ethernet packet can declared as a struct with variables for each of the fields of the packet. A struct can be assigned as a whole, and passed to or from a function or task as a whole. typedef can used be used with struct as in C language. structs and unions can be |
|
|
1 `timescale 1ns/10ps
2
3 // Type define a struct, and put it outside module
4 // So that other modules can also use it
5 typedef struct {
6 byte a;
7 reg b;
8 shortint unsigned c;
9 } myStruct;
10
11 module struct_data ();
12
13 // Define a local struct.
14 struct {
15 byte a;
16 reg b;
17 shortint unsigned c;
18 } myLocalStruct = '{11,1,101};
19
20 // When defined typedef, we can use as new data type
21 myStruct object = '{10,0,100};
22
23 initial begin
24 $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
25 $display ("a = %b b = %b c = %h", myLocalStruct.a,
26 myLocalStruct.b, myLocalStruct.c);
27 #1 $finish;
28 end
29
30 endmodule
You could download file struct_data.sv here
|