-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_static.v
More file actions
64 lines (49 loc) · 1.13 KB
/
Copy pathfunction_static.v
File metadata and controls
64 lines (49 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// The design module - Static Function Example
module stat_func(clk, rst_n, result);
input wire clk;
input wire rst_n;
output reg [7:0] result;
reg [7:0] x = 0;
function [7:0] fstat(input [7:0] in);
begin
x = x + in;
fstat = x;
end
endfunction
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
result <= 8'd0;
else
result <= fstat(8'd1);
end
endmodule
//The testbench - Static Function Example
module tb;
reg clk;
reg rst_n;
wire [7:0] result;
stat_func dut (.*);
initial begin
clk = 0;
forever #5 clk = ~clk;
end
initial begin
rst_n = 0;
#12 rst_n = 1;
end
initial begin
repeat(10) begin
@(posedge clk);
$display("time=%0t result=%0d", $time, result);
end
$finish;
end
endmodule
// Run Script to execute the above design in Modelsim
/*
vlib work
vlog function_static.v
vsim tb
add wave -position insertpoint sim:/tb/*
run -all
*/