Advertisement
STANAANDREY

ac lab5 pb1

Oct 25th, 2023 (edited)
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. module mux_2s #(
  2. parameter w = 4
  3. ) (
  4. input[w-1:0] d0, d1, d2, d3,
  5. input [1:0] s,
  6. output[w-1:0] o
  7. );
  8. wire [3:0] dout;
  9. dec_2s inst0(.s(s), .e(1'd1), .o(dout));
  10. assign o = (dout[0]) ? d0 : {w{1'bz}};
  11. assign o = (dout[1]) ? d1 : {w{1'bz}};
  12. assign o = (dout[2]) ? d2 : {w{1'bz}};
  13. assign o = (dout[3]) ? d3 : {w{1'bz}};
  14. endmodule
  15.  
  16. module mux2s_tb;
  17. reg[7:0] d0, d1, d2, d3;
  18. reg[1:0] s;
  19. wire[7:0] o;
  20. mux_2s #(.w(8)) dut(.s(s), .d0(d0), .d1(d1), .d2(d2), .d3(d3), .o(o));
  21. integer k;
  22. initial begin
  23. $display("d0_16\td1_16\td2_16\td3_16\ts_10\to_16");
  24. $monitor("%h\t%h\t%h\t%h\t%h\t||\t%h", d0, d1, d2, d3, s, o);
  25. for (k = 0; k < 16; k = k + 1) begin
  26. {d3,d2,d1,d0}=$urandom();
  27. s=$urandom();
  28. #10;
  29. end
  30. end
  31. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement