|
|
|

|
|
|
|
|
|

|
|
 |
Structures and unions types
|
|
|
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 |
|
|

|
|
|
- packed : A packed structure consists of bit fields, which are packed together in memory without gaps.
- unpacked : An unpacked structure has an implementation-dependent packing, normally matching the C compiler.
- tagged : An Tagged union is a type-checked union.
|
|
|

|
|
|
|
|
|

|
|
 |
Example - struct
|
|
|

|
|
|
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
|
|
|

|
|
 |
Simulator Output
|
|
|

|
|
|
a = 00001010 b = 0 c = 0064
a = 00001011 b = 1 c = 0065
|
|
|

|
|
|

|
|
|

|
|
|
|
|
|

|
|
|
|
|
|

|
|
Copyright © 1998-2025 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|