Verilog垃圾输入不会导致垃圾输出
我正在用verilog编写一个简单的控制单元。事情是这样的Verilog垃圾输入不会导致垃圾输出,verilog,fpga,vivado,gtkwave,Verilog,Fpga,Vivado,Gtkwave,我正在用verilog编写一个简单的控制单元。事情是这样的 module controlUnit( output reg wreg, input wire [5:0] op, func ); // wreg sub-handles. Beware: wreg is 0 if any of these s high wire isBranch = (op[5:3] == 3'b0) & (|op[2:0]); wire isStrWrd = o
module controlUnit(
output reg wreg,
input wire [5:0] op, func
);
// wreg sub-handles. Beware: wreg is 0 if any of these s high
wire isBranch = (op[5:3] == 3'b0) & (|op[2:0]);
wire isStrWrd = op == 6'b101011;
wire isJumpReg = (op == 6'd0) & (func == 6'b001000);
// wreg handle
always @(*) begin
if(isBranch | isStrWrd | isJumpReg)
wreg <= op == 6'b000011;
else
wreg <= 1'b1;
end
endmodule
module testbench;
integer i;
wire out;
reg [11:0] in;
controlUnit CU0(
.wreg(out),
.op(in[11:6]), .func(in[5:0])
);
initial begin
$dumpfile("test.vcd");
$dumpvars(0, testbench);
#4 in = 0;
for(i=0; i<1024; i=i+1) begin
#1 in = i;
end
#1 in = 10'hXX; // Garbage input here
#1000;
end
endmodule
模块控制单元(
输出调节扳手,
输入线[5:0]op,func
);
//扳手副把手。当心:如果其中任何一个值高,wreg值为0
电线分支=(op[5:3]==3'b0)和(| op[2:0]);
导线isStrWrd=op==6'b101011;
导线isJumpReg=(op==6'd0)和(func==6'b001000);
//扳手柄
始终@(*)开始
if(isBranch | isStrWrd | isJumpReg)
wreg您只将12个输入位中的10位设置为x
;两个MSB为0。您应该将所有输入信号设置为x
。这可能与你的问题无关,但我认为这是你的本意。更改:
#1 in = 10'hXX; // Garbage input here
致:
当if(isBranch | isStrWrd | isJumpReg)
中的信号为x
时,if
为false,执行else
,将wreg
设置为1(wreg
#1 in = {12{1'bx}}; // Garbage input here
always @(*) begin
wreg = (isBranch | isStrWrd | isJumpReg) ? (op == 6'b000011) : 1'b1;
end