Files
hdl-projects/mux_demux/mux_demux.v
Jose Luis Montañes Ojados d094ff3148 first commit
2026-02-28 21:59:55 +01:00

34 lines
527 B
Verilog

/*
Mux / Demux
Mux
a b sel | out
-------------------
0 0 0 | 0
1 0 0 | 1
0 1 1 | 1
1 0 1 | 0
...
*/
module mux_2n1 #(parameter N = 8) (
input [N-1:0] a,
input [N-1:0] b,
input sel,
output [N-1:0] out
);
assign out = sel ? b : a;
endmodule
module demux_1n2 #(parameter N = 8) (
input [N-1:0] in,
input sel,
output [N-1:0] a,
output [N-1:0] b
);
assign a = sel ? 0 : in;
assign b = sel ? in : 0;
endmodule