这个verilog代码有什么问题?
What is the wrong with this verilog code?
有人可以帮助我吗?不知道怎么回事。
module add( a ,b , sum,overFlow);
input [31:0] a;
input [31:0] b;
output overFlow;
output [31:0]sum;
reg sum;
always @(a or b)
begin
sum=a+b;
end
initial
begin
if( a[30]==0 && b[30]==0 && sum[30]==1) overFlow = 1b’1;
else if( a[30] == 1 && b[30] == 1 && sum[30] == 0) overFlow = 1b’1;
end
endmodule
错误是:
"** Error: C:/altera/13.1/add.v(13): near "b": syntax error,
unexpected IDENTIFIER, expecting ';'
** Error: C:/altera/13.1/add.v(14): near "b": syntax error, unexpected IDENTIFIER, expecting ';'
** Error: C:/altera/13.1/add.v(22): near "endmodule": syntax error, unexpected endmodule "
将 1b’1
更改为 1'b1
。请参阅 IEEE Std 1800-2012,“5.7 数字”部分。
修复该问题后,您可能会遇到其他编译错误。
变化:
output overFlow;
output [31:0]sum;
reg sum;
至:
output reg overFlow;
output reg [31:0] sum;
overFlow
必须是 reg
,因为您正在对其进行程序分配(在 initial
块中)。
有人可以帮助我吗?不知道怎么回事。
module add( a ,b , sum,overFlow);
input [31:0] a;
input [31:0] b;
output overFlow;
output [31:0]sum;
reg sum;
always @(a or b)
begin
sum=a+b;
end
initial
begin
if( a[30]==0 && b[30]==0 && sum[30]==1) overFlow = 1b’1;
else if( a[30] == 1 && b[30] == 1 && sum[30] == 0) overFlow = 1b’1;
end
endmodule
错误是:
"** Error: C:/altera/13.1/add.v(13): near "b": syntax error, unexpected IDENTIFIER, expecting ';' ** Error: C:/altera/13.1/add.v(14): near "b": syntax error, unexpected IDENTIFIER, expecting ';' ** Error: C:/altera/13.1/add.v(22): near "endmodule": syntax error, unexpected endmodule "
将 1b’1
更改为 1'b1
。请参阅 IEEE Std 1800-2012,“5.7 数字”部分。
修复该问题后,您可能会遇到其他编译错误。
变化:
output overFlow;
output [31:0]sum;
reg sum;
至:
output reg overFlow;
output reg [31:0] sum;
overFlow
必须是 reg
,因为您正在对其进行程序分配(在 initial
块中)。