-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder_3x8.v
More file actions
90 lines (62 loc) · 1.42 KB
/
decoder_3x8.v
File metadata and controls
90 lines (62 loc) · 1.42 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
module decoder_3x8(out, in);
output [7:0] out;
input [2:0] in;
/* Dataflow Model
wire [2:0] w;
assign w = ~in;
assign out[0] = w[2]*w[1]*w[0];
assign out[1] = w[2]*w[1]*in[0];
assign out[2] = w[2]*in[1]*w[0];
assign out[3] = w[2]*in[1]*in[0];
assign out[4] = in[2]*w[1]*w[0];
assign out[5] = in[2]*w[1]*in[0];
assign out[6] = in[2]*in[1]*w[0];
assign out[7] = in[2]*in[1]*in[0];
*/
/* Structural Model
wire [2:0] w;
assign w = ~in;
and a1(out[0], w[2], w[1], w[0]);
and a2(out[1], w[2], w[1], in[0]);
and a3(out[2], w[2], in[1], w[0]);
and a4(out[3], w[2], in[1], in[0]);
and a5(out[4], in[2], w[1], w[0]);
and a6(out[5], in[2], w[1], in[0]);
and a7(out[6], in[2], in[1], w[0]);
and a8(out[7], in[2], in[1], in[0]);
*/
/* Behavioral Model */
reg [7:0] out;
always @(in) begin
case(in)
3'b000: out = 8'b00000001;
3'b001: out = 8'b00000010;
3'b010: out = 8'b00000100;
3'b011: out = 8'b00001000;
3'b100: out = 8'b00010000;
3'b101: out = 8'b00100000;
3'b110: out = 8'b01000000;
3'b111: out = 8'b10000000;
endcase
end
endmodule
/*Testbench
module testbench;
reg [2:0] in;
wire [7:0] out;
decoder_3x8 decoder(out, in);
initial begin
in = 3'b000;
#100 in = 3'b001;
#100 in = 3'b010;
#100 in = 3'b011;
#100 in = 3'b100;
#100 in = 3'b101;
#100 in = 3'b110;
#100 in = 3'b111;
end
initial begin
$monitor("In = %b Out = %b", in, out);
end
endmodule
*/