我是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)
提前致谢.:)
在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
模块中.
有关生成块的更多信息,请参阅模块实例化,生成块示例和类似的问题链接.