module alu(input [7:0] A,B,
input [3:0] selector,
output [7:0] ALU_output,
output ALU_output_carry
);
reg [7:0] ALU_result;
wire [8:0] tmp;
assign ALU_result=ALU_output;
assign tmp={1'b0,A}+{1'b0,B};
assign ALU_output_carry= tmp[8];
always @(*) begin
case(selector)
4'b0000: ALU_result= A+B;
4'b0001: ALU_result=A-B;
4'b0010: ALU_result=A&B;
4'b0011:ALU_result=A|B;
default: ALU_result=A-B;
endcase
end
endmodule上面是8位算术逻辑单元的Verilog代码(我用这个名字"8it_alu_code.v“保存,没有双引号),下面是它的测试平台(我用这个名字"8it_alu_tb.v”保存,没有双引号)。
`timescale 1ns/1ps
module alu_tb;
reg[7:0] A,B;
reg[3:0] selector;
wire[7:0] ALU_output;
wire ALU_output_carry;
integer i;
alu test(A , B , selector , ALU_output , ALU_output_carry )
initial begin
$dumpfile("dump.vcd");
$dumpvars(1,alu_tb);
A=8'b00000010;
B=8'b00000110;
selector=4'b0000;
for(i=0;i<4;i++)
begin
selector=selector+4'b0001;
#10
end
end
endmodule当我在ICARUS工具上编译它时,如下所示:
iverilog -o 8it_alu_code.v 8it_alu_tb.v我得到了这个错误(我想是在testbench文件中)
8it_alu_tb.v:1: syntax error
I give up.然后,我认为模拟器可能有一些问题,所以我去了'EDAplayground‘网站,在那里的在线模拟器中运行了这两个文件。在那里我得到了以下错误,没有任何输出波形或任何东西:
No top level modules, and no -s option.
Exit code expected: 0, received: 1我希望它能在我的'ICARUS+GTKWAVE‘上成功运行,并给出一些波形输出,或者在EDA Playground在线模拟器上运行。但是,它没有成功编译。所以,请给我一些建议,我应该怎么做才能摆脱它。
发布于 2021-01-13 20:27:46
你从来没有开过ALU_output,你还多次开过ALU_result。这一行:
assign ALU_result=ALU_output;可能应该更改为:
assign ALU_output=ALU_result;iverilog目前不支持SystemVerilog的大部分内容。在SV中引入了++运算符。更改:
for(i=0;i<4;i++)至:
for(i=0;i<4;i=i+1)有两行缺少分号(添加如下):
alu test(A , B , selector , ALU_output , ALU_output_carry );
#10;https://stackoverflow.com/questions/65701724
复制相似问题