Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module mux_2s #(
- parameter w = 4
- ) (
- input[w-1:0] d0, d1, d2, d3,
- input [1:0] s,
- output[w-1:0] o
- );
- wire [3:0] dout;
- dec_2s inst0(.s(s), .e(1'd1), .o(dout));
- assign o = (dout[0]) ? d0 : {w{1'bz}};
- assign o = (dout[1]) ? d1 : {w{1'bz}};
- assign o = (dout[2]) ? d2 : {w{1'bz}};
- assign o = (dout[3]) ? d3 : {w{1'bz}};
- endmodule
- module mux2s_tb;
- reg[7:0] d0, d1, d2, d3;
- reg[1:0] s;
- wire[7:0] o;
- mux_2s #(.w(8)) dut(.s(s), .d0(d0), .d1(d1), .d2(d2), .d3(d3), .o(o));
- integer k;
- initial begin
- $display("d0_16\td1_16\td2_16\td3_16\ts_10\to_16");
- $monitor("%h\t%h\t%h\t%h\t%h\t||\t%h", d0, d1, d2, d3, s, o);
- for (k = 0; k < 16; k = k + 1) begin
- {d3,d2,d1,d0}=$urandom();
- s=$urandom();
- #10;
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement