-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtility_Modules.v
60 lines (39 loc) · 1.08 KB
/
Utility_Modules.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
//2:1 mux
module mux2to1(op, ip, select);
input wire [1:0] ip;
input wire select;
output wire op;
wire [1:0] res; //Intermediate results
wire inv; //Inverted select pins
not G1(inv, select);
//Computing intermediate results
and G2(res[0], ip[0], inv);
and G3(res[1], ip[1], select);
//Final result
or G4(op, res[0], res[1]);
endmodule
//4:1 mux using 2:1 mux
module mux4to1(op, ip, select);
input wire [3:0] ip;
input wire [1:0] select;
output wire op;
wire [1:0] res; //Intermediate result
//Calculates intermediate results from 2 muxes
mux2to1 M1(res[0], ip[1:0], select[0]);
mux2to1 M2(res[1], ip[3:2], select[0]);
//Calculates final results
mux2to1 M3(op, res[1:0], select[1]);
endmodule
//Full adder module
module fullAdder(a, b, Cin, sum, Cout);
input wire a, b, Cin;
output wire sum, Cout;
xor G1(axorb, a, b);
//Calculating sum
xor G2(sum, Cin, axorb);
//Calculating Cout
wire w1, w2;
and G3(w1, Cin, axorb);
and G4(w2, a, b);
or G5(Cout, w1, w2);
endmodule