问题描述
我正在使用以下规范设计一个 32 位加法器/减法器。
输入通过同步复位和使能信号连接到 FF。这些寄存器的输出连接到加/减。加法/减法的输出进入另一组 FF,其输出连接到输出端口。现在当输入被提供给模块时,输出会在 2 个时钟周期后生成。
这是我的设计。
module adder(A,B,Add_Sub,Out);
input [31:0]A;
input [31:0]B;
input Add_Sub;
output [32:0]Out;
reg [32:0]Out;
always @( A or B or Add_Sub)
begin
if(Add_Sub == 1)
Out = A + B;
else
Out = A -B;
end
endmodule
module DFF(D,clk,reset,enable,Q);
input[31:0] D; // Data input
input clk,enable;
output[31:0] Q; // output Q
reg[31:0] Q;
always @(posedge clk or posedge reset)
begin
if(reset)
Q <= 32'b0;
else if (enable)
Q <= D;
end
endmodule
module register_adder(A,CLK,RST,ADD_SUB,EN,OUT,OUT_READY);
input [31:0]A,B;
input CLK,EN;
output [32:0]OUT;
reg [32:0]OUT;
wire [31:0]Q1,Q2;
wire[32:0]Q3;
output OUT_READY;
always @(posedge CLK or A or B or ADD_SUB)
begin
DFF F1(A,Q1);
DFF F2(B,Q2);
adder A1(Q1,Q2,Q3);
DFF F3(Q3,OUT);
OUT_READY <=1'b1;
end
endmodule
在编译模型时,我收到以下错误。
Compiling source file : q6.v
q6.v: L42: error: Illegal Lvalue
q6.v: L42: error: syntax error,unexpected IDENTIFIER,expecting LE or '='
q6.v: L43: error: Illegal Lvalue
q6.v: L43: error: syntax error,expecting LE or '='
q6.v: L44: error: Illegal Lvalue
q6.v: L44: error: syntax error,expecting LE or '='
q6.v: L45: error: Illegal Lvalue
q6.v: L45: error: syntax error,expecting LE or '='
8 errors in compilation
我在分析中找不到问题。
解决方法
您的模块实例不应位于 always
块内。
OUT_READY
也不应该在 always
内,它应该使用 assign
关键字和阻塞赋值运算符 (=
)。
我不再收到以下代码的编译错误:
module register_adder(A,B,CLK,RST,ADD_SUB,EN,OUT,OUT_READY);
input [31:0]A,B;
input CLK,EN;
output [32:0]OUT;
reg [32:0]OUT;
wire [31:0]Q1,Q2;
wire[32:0]Q3;
output OUT_READY;
DFF F1(A,Q1);
DFF F2(B,Q2);
adder A1(Q1,Q2,Q3);
DFF F3(Q3,OUT);
assign OUT_READY = 1'b1;
endmodule
这是 edaplayground 上的固定代码(如果您还没有帐户,则需要创建一个帐户——它是免费的)。
该代码在某些模拟器上生成警告消息。例如,使用 Cadence,我看到:
DFF F3(Q3,OUT);
|
xmelab: *W,CUVMPW (./testbench.sv,42|14): port sizes differ in port connection(33/32) for the instance(register_adder) .
你需要决定你真的想要 32 位还是 33 位。