用仿真函数$display写出3-8译码器的仿真结果并且解释说明
时间: 2023-06-17 20:04:32 浏览: 101
以下是3-8译码器的Verilog代码:
```verilog
module decoder3x8(input [2:0] in, output reg [7:0] out);
always @(*) 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
```
下面是使用仿真函数$display的仿真结果:
```verilog
module decoder3x8_tb;
reg [2:0] in;
wire [7:0] out;
decoder3x8 dut(.in(in), .out(out));
initial begin
$display("in \t out");
in = 3'b000;
#10 $display("%b \t %b", in, out);
in = 3'b001;
#10 $display("%b \t %b", in, out);
in = 3'b010;
#10 $display("%b \t %b", in, out);
in = 3'b011;
#10 $display("%b \t %b", in, out);
in = 3'b100;
#10 $display("%b \t %b", in, out);
in = 3'b101;
#10 $display("%b \t %b", in, out);
in = 3'b110;
#10 $display("%b \t %b", in, out);
in = 3'b111;
#10 $display("%b \t %b", in, out);
end
endmodule
```
仿真结果如下:
```
in out
000 00000001
001 00000010
010 00000100
011 00001000
100 00010000
101 00100000
110 01000000
111 10000000
```
在仿真函数中,我们通过改变输入in的值,观察输出out的变化。从仿真结果可以看出,当输入in为000时,输出out的第0位为1,其余位为0,以此类推。这符合3-8译码器的功能,即将一个3位二进制数字转换为8位二进制输出。
阅读全文