forked from ashishrana160796/verilog-starter-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeMux1x4.v
52 lines (44 loc) · 936 Bytes
/
DeMux1x4.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module dmux(in,s,o1,o2,o3,o4);
input in;
input [1:0]s;
output o1,o2,o3,o4;
reg o1,o2,o3,o4;
always@(in,s)
begin
o1=0;o2=0;o3=0;o4=0;
if(s==2'b00)
o1 = in;
else if(s==2'b01)
o2 = in;
else if(s==2'b10)
o3 = in;
else if(s==2'b11)
o4 = in;
end
endmodule
module test;
reg in;
reg [1:0]s;
wire o1,o2,o3,o4;
dmux d1(in,s,o1,o2,o3,o4);
initial
begin
$dumpfile("vcd/DeMux.vcd");
$dumpvars(0, test);
$display("in \t s \t o1 \t o2 \t o3 \t o4");
$monitor("%b \t %b \t %b \t %b \t %b \t %b", in, s, o1, o2, o3, o4);
in = 0;
s=2'b00;
#10 s=2'b01;
#10 s=2'b10;
#10 s=2'b11;
#10
in = 1;
s=2'b00;
#10 s=2'b01;
#10 s=2'b10;
#10 s=2'b11;
#10
$finish;
end
endmodule