代码很简单,有一堆ifs把某个值放入变量BUS中,模拟时BUS输出等于:zzzzzzzzzzzzzzzz的问题,而它应该有一些与if case对应的值。
module Bus (AR_OUT, IR_OUT, DR_OUT, PC_OUT, AC_OUT, MEM_OUT, read, S, BUS);
input [11:0]AR_OUT ;
input [11:0]PC_OUT ;
input [15:0]IR_OUT ;
input [15:0]DR_OUT ;
input [15:0]AC_OUT ;
input [15:0]MEM_OUT ;
input read ;
input [2:0]S ;
output [15:0]BUS ;
reg [15:0]BUS ;
// inputs are implicitly defined as wire
always @*
begin
if(S == 3'b001)
BUS = AR_OUT;
else if(S == 3'b010)
BUS = PC_OUT;
else if(S == 3'b011)
BUS = DR_OUT;
else if(S == 3'b100)
BUS = AC_OUT;
else if(S == 3'b101)
BUS = IR_OUT;
else if( (S == 3'b111)&&(read == 1'b1) )
BUS = MEM_OUT;
else
BUS = 16'b 0000000000000000;
end
endmodule
module Bus_tb();
reg [11:0]AR_OUT ;
reg [11:0]PC_OUT ;
reg [15:0]IR_OUT ;
reg [15:0]DR_OUT ;
reg [15:0]AC_OUT ;
reg [15:0]MEM_OUT ;
reg read ;
reg [2:0]S ;
wire [15:0]BUS ;
initial begin
AR_OUT = 12'b 0000_0000_1111 ;
PC_OUT = 12'b 0000_1111_0000 ;
IR_OUT = 16'b 0000_0000_1111_0000 ;
DR_OUT = 16'b 0000_0000_1111_1111 ;
AC_OUT = 16'b 0000_1111_1111_0000 ;
MEM_OUT = 16'b 1111_0000_1111_0000 ;
S = 3'b 001 ;
#10 S = 3'b 011;
#10 S = 3'b 010;
#10 S = 3'b 000; //
#10 S = 3'b 101;
#10 S = 3'b 100;
#10 S = 3'b 111;
#5 read = 1'b1;
end
endmodule