-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBooleanFunction.v
80 lines (70 loc) · 1.58 KB
/
BooleanFunction.v
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//F = (A.D + E.(B + C))’ using CMOS logic
module computeF (F, A, B, C, D, E);
input A, B, C, D, E;
output F;
supply1 vdd;
supply0 gnd;
wire a,b;
pmos p1(t3,vdd,A);
pmos p2(t3,vdd,D);
pmos p3(F,t3,E);
pmos p4(t4,t3,B);
pmos p5(F,t4,C);
nmos n1(F,t1,A);
nmos n2(t1,gnd,D);
nmos n3(F,t2,E);
nmos n4(t2,gnd, B);
nmos n5(t2, gnd, C);
endmodule
//************************************************************************
//End of Sample Solution
//************************************************************************
module computeF_tb;
reg A, B, C, D, E;
wire F;
computeF f1(F, A, B, C, D, E);
parameter STDIN = 32'h8000_0000;
integer testid;
integer ret;
initial begin
ret = $fscanf(STDIN,"%d",testid);
case(testid)
1: begin
A = 1'b0; B = 1'b0; C = 1'b0;
end
2: begin
A = 1'b1; D = 1'b1;
end
3: begin
A = 1'b0; E = 1'b0;
end
4: begin
B = 1'b1; E = 1'b1;
end
5: begin
B = 1'b0; C = 1'b0; D = 1'b0;
end
6: begin
C = 1'b1; E = 1'b1;
end
7: begin
D = 1'b0; E = 1'b0;
end
default: begin
$display("Bad testcase id %d",testid);
$finish;
end
endcase
#5
if ( ((testid==1 || testid == 3 || testid==5 || testid==7) && F == 1) || ((testid==2 || testid == 4 || testid==6) && F == 0))
pass();
else
fail();
end
task fail;
$display("Fail: for A = %b, B = %b, C = %b, D = %b, and E = %b, F = %b is WRONG",A, B, C, D, E, F);
endtask
task pass;
$display("Pass: for A = %b, B = %b, C = %b, D = %b, and E = %b, F = %b",A, B, C, D, E, F);
endtask
endmodule