Advertisement
Guest User

CN LAB5

a guest
Mar 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //mux_4x1.v
  2.  
  3. /*
  4.  * Do not change Module name
  5. */
  6. `timescale 1ns / 1ps
  7.  
  8. module Mux(Input0, Input1, Input2, Input3, Sel, Data_out);
  9.  
  10.     input [3:0] Input0;
  11.     input [3:0] Input1;
  12.     input [3:0] Input2;
  13.     input [3:0] Input3;
  14.     input [2:0] Sel;
  15.     output [3:0] Data_out;
  16.     reg [3:0] Data_out;
  17.    
  18.     //constant declaration
  19.     parameter S0 = 2'b00;
  20.     parameter S1 = 2'b01;
  21.     parameter S2 = 2'b10;
  22.     parameter S3 = 2'b11;
  23.    
  24.     always @ (Sel or Input0 or Input1 or Input2 or Input3)
  25.     begin
  26.     case (Sel)
  27.         S0: begin
  28.             Data_out <= Input0;
  29.             end
  30.         S1: begin
  31.             Data_out <= Input1;
  32.             end
  33.         S2: begin
  34.             Data_out <= Input2;
  35.             end
  36.         S3: begin
  37.             Data_out <= Input3;
  38.             end
  39.         endcase
  40.     end
  41. endmodule
  42.  
  43. module Testbench;
  44.  
  45.     reg [3:0] Input0_t, Input1_t, Input2_t, Input3_t;
  46.     reg [2:0] Sel_t;
  47.     wire [3:0] Dat_out_t;
  48.    
  49.     Mux Mux_1(Input0_t, Input1_t, Input2_t, Input3_t, Sel_t, Data_out_t);
  50.    
  51.     initial
  52.     begin
  53.    
  54.         //asign values to input register
  55.         Input0_t <= 0;
  56.         Input1_t <= 1;
  57.         Input2_t <= 2;
  58.         Input3_t <= 3;
  59.        
  60.         //case 0 - Input0 value should be display on output
  61.         Sel_t <= 0;
  62.         #1 $display("Data_out_t = %b", Data_out_t);
  63.        
  64.         //case 1 - Input1 ... analog
  65.         Sel_t <= 1;
  66.         #1 $display("Data_out_t = %b", Data_out_t);
  67.        
  68.          Sel_t <= 2;
  69.         #1 $display("Data_out_t = %b", Data_out_t);
  70.        
  71.          Sel_t <= 3;
  72.         #1 $display("Data_out_t = %b", Data_out_t);
  73.        
  74.          Input0_t = 8;
  75.          Sel_t <= 0;
  76.         #1 $display("Data_out_t = %b", Data_out_t);
  77.        
  78.         Input0_t = 4;
  79.         Sel_t <= 0;
  80.         #1 $display("Data_out_t = %b", Data_out_t);
  81.        
  82.     end
  83. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement