verilog中"generate"和"endgenerate"附近的语法错误

vis*_*iya 0 verilog

我是Verilog的新手,我正在尝试使用verilog实现单精度浮点加法 - 减法.我收到一个错误,我无法纠正.谁能帮帮我吗?

模块addModule(Rs,Re,Rm,As,Ae,Am,Bs,Be,Bm);

//Declarations of ports
  Rs,Re,Rm;
  As,Bs;
  input [7:0] Ae,Be;
  input [22:0] Am,Bm;

reg [7:0] Re;
reg [22:0] Rm;
reg Rs;
//wire declarations.
wire [23:-1] C;
assign C[-1] = 0;
wire [23:1] sum;
//variable declaration.
genvar count;

always @(*)
begin
//Add two mantissas.
if ((As^Bs)==0)
    begin
        generate   //getting error here "Syntax error near "generate"."
        for(count=0;count<24;count=count+1)
            begin
                add add_1(.c_out(C[count]),.sum(sum[count]),.in1(tempAm[count]),.in2(tempBm[count]),.c_in(C[count-1]));
            end
        endgenerate   //syntax error near "endgenerate"
    end

else
    begin
        generate   //Syntax error near "generate".
        for(count=0;count<24;count=count+1)
            begin
                subtract sub_1(.c_out(C[count]),.dif(sum[count]),.in1(tempAm[count]),.in2(tempBm[count]),.c_in(C[count]));
            end
        endgenerate   //Syntax error near "endgenerate".
    end


end
endmodule
Run Code Online (Sandbox Code Playgroud)

提前致谢.:)

sha*_*111 6

在Verilog中,当您实例化模块时,这意味着您要向电路板添加额外的硬件.

必须在模拟开始之前(即在编译时)添加此硬件.在这里,您无法在每个时钟脉冲添加/删除硬件.

一旦实例化,就模拟的每个时间戳执行/检查模块,直到结束.

因此,要执行任何模块,只需实例化它,为其提供clk和其他所需的输入,并在子模块本身中添加always块.

硬件实例化后,应根据其内部的逻辑执行整个生命周期.

在这里,您将在错误的位置实例化模块.generate块的使用必须任何程序块之外完成.

// generate outside any other blocks
   generate   
    for(count=0;count<24;count=count+1)
        begin
            add add_1(.c_out(C[count]),.sum(sum[count]),.in1(tempAm[count]),.in2(tempBm[count]),.c_in(C[count-1]));
        end
    endgenerate

always @(*)
begin
// Other stuff here.
end
Run Code Online (Sandbox Code Playgroud)

如果你想操作的输入信号的的subtract sub_1模块,只需操纵C,sum并在声明的其他变量addModule模块.由于它们是连接的,因此变化也应反映subtract sub_1模块中.

有关生成块的更多信息,请参阅模块实例化,生成块示例类似的问题链接.

  • @vishnupriya你没有**调用**模块你**实例化它们.您描述的硬件不是编写软件.您必须使加法和减法始终存在,然后选择您要使用的输出. (2认同)
  • 模块在模拟开始时实例化一次.正如Morgan所指出的,模块代表物理硬件,而任务和函数则用于计算重复代码.在您的情况下,可以有一种解决方法,将信号/线路添加为每个模块"add"和"subtract"的输入.仅当控制线的值变高时才执行操作.例如.当"As ^ Bs = 1"并且执行添加时,导线变为高状态.同时将相同的导线反转到`sub1`模块.还有其他逻辑.但无论如何,生成块需要在程序块之外. (2认同)