我正在使用 Verilog 实现 4 位移位加法器,我遇到了以下代码的问题:
//shift register to store the two inputs a and b to be added
module shift(y, d, clk);
input [3:0] d;
input clk;
output [3:0] y;
reg [3:0] y;
initial begin
assign y=d;
end
always @(posedge clk)
assign y= {1'b0, d[3:1]};
endmodule
//serial in parallel out register to store the 4 bit sum
module sipo(y, s, clk);
input s, clk;
output [3:0] y;
reg [3:0] y;
always @(posedge clk)
begin
y={s,y[3:1]};
end
endmodule
//1 bit full adder
module fa(s, cout, a, b, cin);
input a, b, cin;
output s, cout;
assign {cout, s} = a + b + cin;
endmodule
//d flipflop to store the cout of each stage
module dff(q, d, clk);
input d, clk;
output q;
reg q;
initial begin
q = 1'b0;
end
always @(posedge clk)
begin
q = d;
end
endmodule
//main module serial adder//
module serial(sum, cout, a, b, clk);
input [3:0] a, b;
input clk;
wire [3:0] x, z;
output [3:0] sum;
output cout;
wire s = 0;
wire cin = 0;
fa k(s, cout, x[0], z[0], cin); //1 bit full adder
dff q(cin, cout, clk); //d flipflop to store the cout value after each 1 bit full adder operation
sipo m(sum, s, clk); //serial sum(s) converted to parallel output(4 bit sum)///
shift g(x, a, clk); //shifts the input a
shift h(z, b, clk); //shifts the input b
endmodule
module SATestBench;
reg [3:0] a, b;
reg clock;
wire cout;
wire [3:0] sum;
serial sa(sum, cout, a, b, clock);
initial begin
#5 clock = 1'b0;
repeat(6)
# 5 clock = ~clock;
end
initial begin
#0 a = 4'b1000; b=4'b0110;
$monitor($time, " A = %b, B = %b, CarryOut = %b, Sum = %b.", sa.x, sa.z, cout, sum);
end
endmodule
我收到的错误是“vvp.tgt 抱歉:尚未完全支持过程连续赋值。此赋值的 RHS 仅在执行赋值语句时计算一次。”我在网上搜索了一下,从here发现always块中不允许分配。
然后我尝试删除分配块,然后 Sum/CarryOut 的输出只有“x”。我无法解决这个问题,我已经尝试了很多小时了。我刚刚开始学习 Verilog,所以如果这是一个新手错误,我深表歉意。
在下面的示例快照中,程序块中使用的
assign
是您的消息所抱怨的程序连续分配。
initial begin
assign y=d;
end
always @(posedge clk)
assign y= {1'b0, d[3:1]};
这是一个非常特殊的不可综合的语句,很少使用(如果有的话)。你应该避免它。
如果在此类状态中使用此关键字,请删除该关键字。
initial begin
y=d;
end
always @(posedge clk)
y <= {1'b0, d[3:1]};
现在你遇到了多驱动程序问题。变量 y 由两个不同的程序块驱动。您应该更改它并使用重置:
always @(posedge clk) begin
if (reset)
y <= d;
else
y <= {1'b0, d[3:1]};
因此,您应该提供重置。