You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Modelsim仿真Transcript输出未知/异常数值问题求助

问题:Testbench中$display输出未知/固定异常数值

我在编写处理器的testbench,通过$display()语句调试,但Transcript窗口始终输出未知(x)或固定的异常数值,且每次仿真输出完全一致,应该不是乱码问题。以下是代码中唯一的显示逻辑:

// to display 
always @ (posedge clock)
begin
    #1
    if (isInstruction)
    begin 
        // print the instruction number (order)
        $display ("instruction %h : ", i);
        // print thie instruction opcode
        $display ("OpCode = %h ", Processor.opCode);

        // print the instruction name
        case (Processor.opCode)

            _addi : begin
                $display ("instruction name : ADDI");
            end
        
        endcase
    
        $display((Processor.RegWriteEn) ? "write on register file : Yes" : "write on register file : No");
        if (Processor.RegWriteEn)
        begin 
            $display ("Write on register number : %h", Processor.mux1Out);
            $display ("data written on register : %h", Processor.mux4Out);
        end
        
        $display((Processor.MemWriteEn) ? "write on Memory : Yes" : "write on Memory : No");
        if (Processor.MemWriteEn)
        begin 
            $display ("Write on address : %h", Processor.aluResult);
            $display ("data written on register : %h", Processor.data2);
        end

    end
    
    else
    
    begin
        $display ("no instruction loaded in this clock");
    end
end

仿真输出如图所示:
仿真输出截图

排查建议

  • 检查时钟信号:确认testbench生成的clock信号有效且正确连接到Processor模块,避免时钟始终为高/低或未初始化的情况——always @(posedge clock)的逻辑完全依赖正常的时钟跳变。
  • 信号初始化:i、isInstruction以及Processor内部的opCode、RegWriteEn等信号是否完成初始化?Verilog中未初始化的寄存器默认是x(未知态),会直接导致输出异常。
  • 模块连接:核对testbench与Processor的端口连接是否完全正确,比如opCode、mux1Out等信号有没有接错端口,或是模块内部这些信号根本未被正确赋值。
  • 时序延迟:代码中的#1延迟可能导致采样到信号的不稳定状态,尝试去掉该延迟或调整延迟时长,观察输出是否恢复正常。
  • 常量定义:确认_addi常量的定义值与实际指令的opcode匹配,否则case分支不会触发,无法输出正确的指令名称。
  • 仿真时长:保证仿真运行足够长的时间,让处理器有充足周期加载并执行指令,避免在指令未加载完成时就终止仿真。

内容的提问来源于stack exchange,提问作者Giannis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 22:50:22