【问题标题】:Verilog simulation errorsVerilog 仿真错误
【发布时间】:2026-01-15 03:00:01
【问题描述】:

在模拟中,'a' 不会改变它的值,我似乎不知道为什么。 'carry out(co)' 总是以 HiZ 的形式出现,而 'sum' 会产生一些奇怪的值。 'of(overflow)' 值也是 有人可以帮我解决这个问题吗? 任何帮助将不胜感激。 提前非常感谢。

    `timescale 100ps/1ps    
module RCA_tb;
reg [7:0] a;
reg [7:0] b;
reg ci;
wire [7:0] sum;
wire co;
wire of; //overflow
integer i;

RippleCA RCA(a,b,ci,sum,co,of); 

initial begin 

    a=0;
    b=0;
    ci=0;

    end



    initial begin // all possible cases 

    for(i=0; i<256; i=i+1)


    #10 {a, b, ci} = i;


    end
endmodule

module RippleCA(a,b,ci,sum,co,of);
input [7:0] a;
input [7:0] b;
input ci;
output [7:0] sum;
output co;
output of;
wire[6:0] c;
FullAdder a1(a[0],b[0],ci,sum[0],c[0]);
FullAdder a2(a[1],b[1],c[0],sum[1],c[1]);
FullAdder a3(a[2],b[2],c[1],sum[2],c[2]);
FullAdder a4(a[3],b[3],c[2],sum[3],c[3]);
FullAdder a5(a[4],b[4],c[3],sum[4],c[4]);
FullAdder a6(a[5],b[5],c[4],sum[5],c[5]);
FullAdder a7(a[6],b[6],c[5],sum[6],c[6]);
FullAdder a8(a[7],b[7],c[6],sum[7],cout);
xor x2(of,c[6],co); //overflow detection
endmodule
module FullAdder (
a,b,ci,sum,co
);
input a,b,ci;
output sum,co;
wire w1, w2, w3;
xor x1(sum, a, b, ci);
and a1(w1,a,b);
and a2(w2,b,ci);
and a3(w3,ci,a);
or o1(co,w1,w2,w3);
endmodule

这是我的 Verilog 代码。

enter image description here

enter image description here

【问题讨论】:

  • 将 3 个初始测试台块合并为一个。
  • 感谢您的评论。刚刚编辑了我的代码并对其进行了模拟,“ci”每 #10 更改一次,但其他问题保持不变。尤其是 'a' 不会改变,并且 sum 会产生包括 xs 在内的值。

标签: verilog system-verilog


【解决方案1】:

你声明

reg [7:0] a;
reg [7:0] b;
reg ci;

并分配

{a, b, ci} = i;

{a,b,ci} 是 17 位宽,但您将 i 计数到 8 位宽的 255,在这种情况下,a 将始终为零。如果您将 for 循环增加到 for(i=0; i&lt;262144; i=i+1),您应该能够对其进行测试。

【讨论】: