-
Notifications
You must be signed in to change notification settings - Fork 13
/
Mux.v
36 lines (28 loc) · 759 Bytes
/
Mux.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
module mux2to1(out, select, in1, in2);
input in1, in2, select;
output out;
wire not_select, w1, w2;
not (not_select, select);
and (w1, select, in2);
and (w2, not_select, in1);
or(out, w1, w2);
endmodule
module mux3to1(out, select, in1, in2, in3);
input in1, in2, in3;
input [1:0] select;
output out;
wire w;
mux2to1 m1(w, select[0], in1, in2); //in1 - 00; in2 - 01; in3 - 1x
mux2to1 m2(out, select[1], w, in3);
endmodule
module bit32_3to1mux (out, select, in1, in2, in3);
input [31:0] in1, in2, in3;
input [1:0] select;
output [31:0] out;
genvar j;
generate
for(j = 0; j <32; j = j + 1) begin: mux_loop
mux3to1 m1(out[j], select, in1[j], in2[j], in3[j]);
end
endgenerate
endmodule