我不知道为什么它不起作用。我在edaplayground上运行了一个模拟,每次选择更改为0时,输出中都会出现一个"x“。不过,当sel是"1“时,我会正确地得到"1”。
守则:
module mux8_2(input [3:0]a,[3:0]b,sel,output [3:0]out);
assign out=(sel)?a:b;
endmodule而实验台:
module mux8_2_tb;
reg [3:0]A;
reg [3:0]B;
reg SEL;
wire [3:0]OUT;
mux8_2 UUT(A,B,SEL,OUT);
initial
begin
$dumpfile("dump.vcd");
$dumpvars(1);
A=4'b1; B=4'b0; SEL=1'b1;
#1 SEL=1'b0;
#1 SEL=1'b1;
#1 SEL=1'b0;
#1 SEL=1'b1;
#1 SEL=1'b0;
#1 SEL=1'b1;
#1;
end
endmodule发布于 2016-12-14 20:50:10
我不能复制你的结果,OUT信号总是为我所知。
但是,我确实收到了编译警告:
The following 1-bit expression is connected to 4-bit port "sel" of module
"mux8_2", instance "UUT"这个问题可以解决:
module mux8_2(input [3:0]a,[3:0]b, input sel,output [3:0]out); 在您的代码中,sel继承了前一个信号([3:0]b)的宽度。您的代码等效于:
module mux8_2(input [3:0]a,[3:0]b,[3:0]sel,output [3:0]out); 在input强制使用1位的默认宽度之前,添加另一个sel关键字。
https://stackoverflow.com/questions/41151597
复制相似问题