-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmux.v
More file actions
48 lines (45 loc) · 652 Bytes
/
Copy pathmux.v
File metadata and controls
48 lines (45 loc) · 652 Bytes
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
// 2-to-1 mux
module mux2(
input wire x1,
input wire x2,
input wire s,
output wire y
);
assign y = s ? x2 : x1;
endmodule
// 3-to-1 mux
module mux3(
input wire x1,
input wire x2,
input wire x3,
input wire [1:0] s,
output reg y
);
always @(*) begin
case (s)
2'b00: y = x1;
2'b01: y = x2;
2'b10: y = x3;
default: y = 1'b0;
endcase
end
endmodule
// 4-to-1 mux
module mux4(
input wire x1,
input wire x2,
input wire x3,
input wire x4,
input wire [1:0] s,
output reg y
);
always @(*) begin
case (s)
2'b00: y = x1;
2'b01: y = x2;
2'b10: y = x3;
2'b11: y = x4;
default: y = 1'bx;
endcase
end
endmodule