0

我正在尝试实现给定特定功能代码的 ALU。

出于某种原因,下面的代码没有运行,并且根据编译器有错误。

错误(可抑制):alu.v(61): (vlog-2388) 'result' 已在此范围 (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) 在“结果”之后的范围内发现语法错误。是否缺少'::'?

如果我将 result、operand0、operand1 和 control 的声明删除为线和 regs,我仍然会收到错误消息,指出“结果”超出范围或无法访问。我真的对这部分感到困惑,任何帮助将不胜感激。

我觉得问题出在注册表和电线的某个地方,但我不确定。

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)非法引用网络“结果”。3次

4

1 回答 1

2

您的代码几乎没有问题。有两种声明输入和输出的方法:

  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,则必须在always块内使用它,否则将其定义为线。

您的代码可以编写如下:

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 
于 2015-10-25T07:19:14.943 回答