0

我正在尝试通过使用 for 循环使用波纹进位加法器来执行加法,并且我希望该操作仅在时钟的位置执行。为此,我使用了一个生成块并在生成块内使用了 for 循环。如果我不使用 always 语句,它会正常工作,但是当我添加 always 块时,它会在模拟时导致错误。下面是代码:

genvar i;
generate
    always @(posedge clk)
    for(i=0;i<=31;i=i+1) begin : generate_block         
        fulladd f1(.sum(sum[i]),.cin(cout1[i]),.a(b[i]),.b(temp[i]),.cout(cout1[i+1]));

    end
    end

endgenerate

这里 fulladd 是一个不同的模块。

以下是我在模拟时遇到的错误:

   Error-[IBLHS-CONST] Illegal behavioral left hand side
   add32.v, 36
   Constant Expression cannot be used on the left hand side of this assignment
   The offending expression is : i
   Source info: i = 0;


   Error-[IBLHS-CONST] Illegal behavioral left hand side
   add32.v, 36
   Constant Expression cannot be used on the left hand side of this assignment
   The offending expression is : i
   Source info: i = (i + 1);


   Error-[SE] Syntax error
   Following verilog source has syntax error :
   "add32.v", 37: token is '('
        fulladd 
   f1(.sum(sum[i]),.cin(cout1[i]),.a(b[i]),.b(temp[i]),.cout(cout1[i+1]));

add32.v 是设计模块名称。我用过概要 vcs。我是verilog编程的新手,请解释我错误的基本概念。提前致谢

4

2 回答 2

0

加法逻辑和注册信号应分开处理。从加法器中提取相关的输入和输出信号,并在 posedge 处分别注册。

请参阅此 CLA 加法器实现代码以供参考

我已经实现了一个通用的波纹进位加法器,如下所示。

// ripple_carry_adder.v
// NOTE : I have registered the outputs only. Inputs are asynchronous. 

`timescale 1ns  / 10 ps
module ripple_carry_adder 
            #(  parameter COUNT = 32                  // width of RCA port
            )
                (      
                    input  clk,rst,                 
                    input  Carry_in,            
                    input  [COUNT-1:0] A, B,
                    output reg [COUNT-1:0] Sum,
                    output Carry_out
                );

reg [COUNT-1:0] Carry,Cout; 
assign Carry_out = Cout[COUNT-1];

always@(posedge clk or posedge rst)
begin
    if (rst)
        begin
            Carry  = 'b0;
            Sum    = 'b0;
            Cout   = 'b0;
        end
    else
        begin   
            Cout    = ((A & B) | ((A ^ B) & Carry));
            Sum     = (A ^ B ^ Carry);
            Carry   = {Cout[COUNT-1:1],Carry_in}; 
        end
end
endmodule
于 2016-10-31T10:43:02.223 回答
0

在这种情况下,我不明白为什么您需要始终阻止。你永远不会以时钟的姿态实例化任何东西。

我编写生成块的方法是首先弄清楚一个实例(没有生成)会是什么样子:

fulladd f1(.sum(sum[0]),.cin(cout1[0]),.a(b[0]),.b(temp[0]),.cout(cout1[1]));

然后,扩展它以实例化 fulladd 的多个实例:

genvar i;
generate
for(i=0;i<=31;i=i+1) begin : generate_block         
  fulladd f1(.sum(sum[i]),.cin(cout1[i]),.a(b[i]),.b(temp[i]),.cout(cout1[i+1]));
end
endgenerate
于 2016-11-04T14:18:04.117 回答