summaryrefslogtreecommitdiff
path: root/verilog/nbit_demux.v
diff options
context:
space:
mode:
Diffstat (limited to 'verilog/nbit_demux.v')
-rwxr-xr-xverilog/nbit_demux.v33
1 files changed, 33 insertions, 0 deletions
diff --git a/verilog/nbit_demux.v b/verilog/nbit_demux.v
new file mode 100755
index 0000000..5be44c8
--- /dev/null
+++ b/verilog/nbit_demux.v
@@ -0,0 +1,33 @@
+//n bit DeMux
+// Specify the number of select lines as a parameter.
+module nbit_demux(DeMuxIn, // DeMux input: 1 bit.
+ DeMuxOut, // DeMux output: 2^SELECT_WIDTH bits.
+ DeMuxSel); // DeMux select lines: SELECT_WIDTH bits.
+
+// Specifies the select line width.
+parameter SELECT_WIDTH = 3;
+
+//-------------Input Ports-----------------------------
+input DeMuxIn;
+input [SELECT_WIDTH-1:0] DeMuxSel;
+//-------------Output Ports----------------------------
+output [2 ** SELECT_WIDTH-1:0] DeMuxOut;
+//-------------Wires-----------------------------------
+wire [2 ** SELECT_WIDTH-1:0] select;
+//-------------Other-----------------------------------
+//------------Code Starts Here-------------------------
+
+generate
+ genvar i; // Instance variable
+
+ // address decoder
+ assign select[2 ** SELECT_WIDTH-1:0] = 2 ** DeMuxSel[SELECT_WIDTH-1:0];
+
+ // Generation for loop
+ for(i= 0;i< 2 ** SELECT_WIDTH;i= i+1)
+ begin:demux_loop
+ assign DeMuxOut[i] = DeMuxIn & select[i];
+ end
+endgenerate
+
+endmodule