【发布时间】:2015-12-07 04:52:30
【问题描述】:
我是 xilinx 的新手,所以请原谅代码中的任何愚蠢之处。
啊,所以我正在尝试设计一个 8 位 ALU,该模块在模拟中运行良好,但我们需要在 FPGA 板上获取输入和显示输出.
从技术上讲,我应该使用 RS-232,但由于我们只有一个 8 位输入和 8 个开关,因此我们正在尝试以这种方式对其进行编码。
但是,代码无法编译并给出错误
"expecting 'endmodule', found 'forever'"。
我使用了'forever' 而不是'always',因为始终不允许在其中实例化任何实例。
谁能帮我们找出代码有什么问题?
module main(out,in,switch);
output [7:0] out;
input [7:0] in;
input switch;
reg [7:0] a,b,select;
reg [1:0] count;
wire eq, comp, C8;
initial
begin
count = 2'b00;
select = 8'b0000_0000;
end
MyALU A(eq, comp, C8, out, a, b, 1'b0, select[0], select[1], select[2], select[3]);
forever
begin
if (switch)
begin
case (count)
00:
begin
a = in;
count = 2'b01;
end
01:
begin
b = in;
count = 2'b10;
end
10:
begin
select = in;
A(eq, comp, C8, out, a, b, 1'b0, select[0], select[1], select[2], select[3]);
count = 2'b00;
end
default
a = in;
endcase
end
end
【问题讨论】:
-
verilog 内的循环必须在某个程序块内。在
forever之前使用initial。或者删除forever并使用always @(*)是更好的方法。endmodule在这里不见了。 -
模块实例化只是在任何程序块之外。如果需要多个实例(此处不是这种情况),请使用
generate块。