我正在尝试实现一个给定特定功能代码的ALU。
由于某些原因,下面的代码没有运行,并且根据编译器有错误。
错误(可抑制的):alu.v(61):(vlog-2388)“结果”已经在此范围(alu)中声明。 错误(可抑制):alu.v(67):(vlog-2388) 'operand0‘已经在此作用域中声明(alu)。 错误(可抑制):alu.v(67):(vlog-2388) 'operand1‘已经在此作用域中声明(alu)。 错误(可抑制):alu.v(68):(vlog-2388)“控制”已经在此范围内声明(alu)。 错误:(vlog-13069) alu.v(71):接近" <= ":语法错误,意外的<=。 错误: alu.v(71):(vlog-13205)语法错误出现在下面的“结果”范围内。有缺失的“:”吗?
如果我将结果、operand0、operand1和控件的声明作为连线和规则删除,那么仍然会出现错误,说明“结果”超出了作用域或无法访问。我真的很困惑这个部分,任何帮助都将不胜感激。
我觉得问题出在雷克和电线的某个地方,但我不确定。
module alu
(
//--------------------------
// Input Ports
//--------------------------
input [31:0] operand0,
input [31:0] operand1,
input [3:0] control,
//--------------------------
// Output Ports
//--------------------------
output [31:0] result,
output zero,
output overflow
);
// Signal Declarations: local params
// Signal Declarations: reg
// Signal Declarations: wire
always @(*)
begin
case(control)
4'b0000: result= operand0 | operand1; // OR
4'b0001: begin
result= operand0 & operand1; // AND
end
default: result = 4'b0;
endcase
end
endmodule 我将上面的代码更改为修改后的版本。不过,我还是会犯错误:
现在它说:(vlog-2110)非法引用净“结果”。三次
发布于 2015-10-25 07:19:14
您的代码几乎没有问题。有两种申报投入和产出的方法:
module alu (
input [31:0] operand0,
input [31:0] operand1,
input [3:0] control,
output reg [31:0] result,
output zero,
output overflow
);第二种方法是:
module (operand0,operand1,control,result,zero,overflow);
input [31:0] operand0;
input [31:0] operand1;
input [3:0] control;
output reg [31:0] result;
output zero;
output overflow;我希望你能看到不同之处。因此,在您的代码中,您将重新声明输入和输出。
此外,非阻塞分配,即<=通常用于时序逻辑。对于组合逻辑,阻塞分配是首选的,即=。
如果要将输出定义为reg,则必须在始终块中使用它,否则将其定义为有线。
您的代码可以编写如下:
module alu
(
input [31:0] operand0,
input [31:0] operand1,
input [3:0] control,
output reg [31:0] result,
output zero,
output overflow
);
always @(*)
begin
case(control)
4'b0000: result= operand0 | operand1; // OR
4'b0001: begin
result= operand0 & operand1; // AND
end
default : result =4'b0;
endcase
end
endmodule https://stackoverflow.com/questions/33326634
复制相似问题