Verilog垃圾输入不会导致垃圾输出

问题描述

我正在用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 = 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

但是,在仿真中,当输入变为垃圾时,wreg信号为稳定的逻辑高电平。我已经在iverilog-10 / GTKwave和Vivado 2019.1。中看到了这种行为。以下是波形:

Garbage as input,but logic HIGH as output.

那为什么呢?

解决方法

您只需将12个输入位中的10个设置为UnwindOperation unwindOperation = Aggregation.unwind("barcodes"); ProjectionOperation projectStage = Aggregation.project() .and("_id").as("productId") .and("title").as("productTitle") .and("variation").as("productVariation") .and("barcodes.title").as("barcodeTitle") .and("barcodes.value").as("barcodeValue") .and("barcodes.type").as("barcodeType") .and("barcodes.codeStandard").as("codeStandard") .and("barcodes.quantity").as("quantity") .and("barcodes.status").as("status"); SortOperation sortOperation = Aggregation.sort(Sort.by(Sort.Direction.DESC,"productTitle")); Aggregation agg = Aggregation.newAggregation(unwindOperation,projectStage,sortOperation); AggregationResults<BarcodeAggregateList> results = mongoTemplate.aggregate(agg,"product",BarcodeAggregateList.class); ; 2个MSB为0。您应该将所有输入信号都设置为x。这可能与您的问题无关,但我认为这正是您的意图。更改:

x

收件人:

    #1 in = 10'hXX;    // Garbage input here

#1 in = {12{1'bx}}; // Garbage input here 中的信号为if(isBranch | isStrWrd | isJumpReg)时,x为假,并执行if,将else设置为1({{ 1}}),而不是wreg。这回答了以下问题:为什么在所有输入均为wreg <= 1'b1时,Verilog仿真器将x分配给1。这就是模拟器设计的工作方式。


当输入为wreg时,使用三进制运算符等效代码会将x设置为wreg

x

请注意,对于组合逻辑,建议使用阻塞分配(x)。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...