【发布时间】:2016-10-06 03:58:38
【问题描述】:
这是我第一次在 verilog hdl 中编程,我无法弄清楚我的代码有什么问题。我需要在行为代码中设计一个简单的 ALU。
到目前为止,我已经创建了一个减法器和加法器模块。(我需要添加更多模块,但我希望在添加其他模块之前让它们在 ALU 模块中工作)。
我在同一个项目的单独 .v 文件中有以下模块(很确定这是行为?):
module adder3bit( sum, co, a, b);
parameter n = 2;
output reg [n:0] sum;
output reg co;
input [n:0] a;
input [n:0] b;
always @(a, b)
{co, sum} = a + b;
endmodule
module subtract3bit(diff, bo, a, b);
parameter n = 2;
output reg [n:0] diff;
output reg bo;
input [n:0] a;
input [n:0] b;
always @(a, b)
{bo, diff} = a - b;
endmodule
我测试了这些,发现它们正在工作。
现在我尝试在主 ALU 模块中调用它们:
module alu( out, overflow, a, b,sel);
input [2:0] a, b;
input sel;
output [2:0] out;
output overflow;
always @(a,b,sel)
begin
if(sel=='b0)
adder3bit A1(out,overflow,a,b);
if(sel=='b1)
subtract3bit S1( out, overflow, a, b);
end
endmodule
我的语法可能是错误的,但它显示错误。我只是对verilog非常陌生。我感受到了我第一次学习 C 时的感受。我们将不胜感激。
我知道它正确调用了模块,但我认为这与 if 语句有关。
谢谢,希望能学到新东西!
【问题讨论】: