A lot of code needs to be written to do the design verification machine, most of which are used in tasks and functions. Systemverilog adds a lot of improvements in this regard, making it closer to the C language, which makes the writing of code easier, especially in the handling of parameter transfer.
- In Systemverilog, process blocks and their methods are divided by domain, and are divided into hardware and software parts . The specific contents are as follows:
The test questions for the function parameter type are as follows:
typedef struct{
bit [1:0] cmd;
bit [7:0] addr;
bit [31:0] data;
} trans;
function automatic void op_copy(trans t,trans s);
t = s;
endfunction
initial begin
trans s;
trans t;
s.cmd = 'h1;
s.addr = 'h10;
s.data = 'h100;
op_copy(t,s);
t.cmd = 'h2;
end
Question: What are the final values of the three member variables {cmd, addr, data} in t?
{‘h2,'h0,'h0}
Due to the function parameters, the default direction is input, here the trans t variable is regarded as an input variable. Therefore, the function of assignment is realized by calling the op_copy function. Since the direction of the outgoing value is not determined, the result is 0.
- In systemverilog, we divide the life cycle into automatic and static.
-
The scope design problems for static variables and dynamic variables are as follows:
-
function automatic int auto_cnt(input a); int cnt = 0; cnt +=a; return cnt; endfunction function static int auto_cnt(input a); static int cnt = 0; cnt +=a; return cnt; endfunction function int auto_cnt(input a); static int cnt = 0; cnt +=a; return cnt; endfunction initial begin $display("@1 auto_cnt = %0d",auto_cnt(1)); $display("@2 auto_cnt = %0d",auto_cnt(1)); $display("@1 auto_cnt = %0d",static_cnt(1)); $display("@2 auto_cnt = %0d",static_cnt(1)); $display("@1 def_cnt = %0d",def_cnt (1)); $display("@2 def_cnt = %0d",def_cnt (1)); end
Solution: For the first function, if it is defined as automatic, its contents are all dynamic variables. Therefore, after each call, the original value will be restored to 0;
-
For the second function, if it is defined as static, its contents are all static variables. Therefore, after each call, it will increment;
-
For the third function, all functions in the module are static functions by default , and the variables in the functions are static variables . However, in most cases, we hope that the functions in the module are dynamic functions, which is more in line with software requirements.
-