|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
bsd.v
1 module bsd
2 (
3 rst_n,
4 x_n,x_p,
5 y_n,y_p,
6 sum
7 );
8 input rst_n;
9 input x_n,x_p,y_n,y_p;
10
11 output sum;
12 reg x,y;
13 reg inter_c_n,inter_c_p;
14 reg inter_s_n,inter_s_p;
15 reg sum_p,sum_n;
16 reg sum;
17
18 always @(x_n or x_p or y_n or y_p or negedge rst_n)
19 begin
20
21 x=1;
22 y=(-2*y_n)+y_p;
23 inter_c_n=(x_n&y_n)|(((x_n&(~y_p))|(y_n&(~x_p)))&0);
24 inter_c_p=((~x_n)&x_p&(~y_n)&y_p)|((((~x_n)&x_p&(~y_p))|((~y_n)&y_p&(~x_p)))&1&1)|inter_c_n;
25 inter_s_n=1&1&(((~x_n)&x_p&(~y_p))|((~y_n)&y_p&(~x_p))|(x_n&(~y_p))|(y_n&(~x_p)));
26 inter_s_p=x_p^y_p;
27 sum_n=(inter_s_n&1)|((~inter_s_p)&0);
28 sum_p=~((~inter_s_p)&1)|(inter_s_n&1&0)|(0&(~inter_s_n)&inter_s_p);
29 sum=(-2*sum_n)+sum_p;
30
31 end
32 endmodule
bsd_tb.v
1 `timescale 1ns/1ns
2 //`include "bsd.v"
3 module bsd_testbench;
4 reg rst_n;
5 reg x_n,x_p,y_n,y_p;
6 reg inter_c_n,inter_c_p;
7 reg inter_s_n,inter_s_p;
8 reg sum_p,sum_n;
9 wire sum;
10
11
12 bsd bsd_testbench(
13 .rst_n ( rst_n ),
14 .sum ( sum ),
15 .x_n ( x_n ),
16 .x_p ( x_p ),
17 .y_n ( y_n ),
18 .y_p ( y_p )
19 );
20
21 initial begin
22 rst_n = 1;
23 #2;
24 rst_n = 0;
25 x_n=0;
26 #500 x_n=~x_n;
27 end
28
29 initial begin
30 rst_n = 1;
31 #2;
32 rst_n = 0;
33 x_p=0;
34 #200 x_p=~x_p;
35 #200 x_p=~x_p;
36 #100 x_p=~x_p;
37
38 end
39
40 initial begin
41 rst_n = 1;
42 #2;
43 rst_n = 0;
44 y_n=0;
45 #400 y_n=~y_n;
46 #100 y_n=~y_n;
47 #100 y_n=~y_n;
48 #100 y_n=~y_n;
49 end
50
51 initial begin
52 rst_n = 1;
53 #2;
54 rst_n = 0;
55 y_p=0;
56 #100 y_p=~y_p;
57 #100 y_p=~y_p;
58 #100 y_p=~y_p;
59 #200 y_p=~y_p;
60 #100 y_p=~y_p;
61
62
63 end
64
65
66
67 endmodule
68
我给x赋值1,为什么在波形中会显示出-1,找不出别的地方对x或是y有别的定义,而且y的值也不满足等式?
|
|