You are on page 1of 2

@shraddha_pawankar Date:06/03/2024

System Verilog : Copying Object

Sometimes we may be in a situation where we want to keep original data as it is.and we


want to utilize the original copy of an original data for processing.
How we keep the data from our original class.
1. class first;
2.
3. int data;
4.
5. endclass
6.
7. module tb;
8.
9. first f1;
10. first p1;
11.
12.
13. initial begin
14. f1 = new(); ///1. constructor
15. ///////////////
16. f1.data = 24; ///2. processing
17. /////////////////
18.
19. p1 = new f1; /// 3. copying data from f1 to p1
20.
21. /////////////
22.
23. $display("Value of data member : %0d", p1.data); //4. processing
24.
25. p1.data = 12;
26.
27. $display("Value of data member : %0d", f1.data); //4. processing
28.
29.
30. end
31.
32.
33.
34. endmodule

1|Page
@shraddha_pawankar Date:06/03/2024

Output :
# KERNEL: Value of data member : 24
# KERNEL: Value of data member : 24

Eda playground link: https://www.edaplayground.com/x/DkDJ

• We have a series of component of our TB and we want to apply this data.


• Component could interact with this object data.
• So good idea will be that you create a copy of this object and then instead of sending
original data.
• We send the copied object.
• So this object will be created,which is basically copy of an original data,we basically
applied to a component.

2|Page

You might also like