-1
我是verilog的新手。我正在使用Xilinx IDE。我的ALU模塊如下:簡單的Verilog ALU實現,無輸出
module ALU(in1,in2,operation,clk,out
);
input [15:0] in1;
input [15:0] in2;
input [3:0] operation;
input clk;
output[15:0] out;
reg [15:0] out;
[email protected](posedge clk)
begin
case(operation)
4'b0010:
out <= in1+in2;
4'b0011:
out <= in1-in2;
4'b0100:
out <= !in1;
4'b0101:
out <= in1<<in2;
4'b0110:
out <= in1>>in2;
4'b0111:
out <= in1&in2;
4'b1000:
out <= in1|in2;
//4'b1001:
// out = in1>=in2?16'd0:16'd1;
default: out <= 16'hFFFF;
endcase
end
endmodule
我的測試平臺是如下
module test_projectALU;
reg [15:0] in1;
reg [15:0] in2;
reg [3:0] operation;
reg [15:0] out;
reg clk;
ALU PA(in1,in2,operation,out);
initial
begin
operation=4'b0000;
in1=4'b0000;
in2=4'b0000;
clk = 0;
end
always
begin
#2 operation=4'b0010; in1=4'b0011; in2=4'b0000;
#2 operation=4'b0011; in1=4'b0001; in2=4'b0011;
#2 operation=4'b0000; in1=4'b1100; in2=4'b1101;
#2 operation=4'b0011; in1=4'b1100; in2=4'b1101;
end
always
begin
#5 clk=~clk;
end
initial $monitor($time,"f=%b, a=%b, b=%b,c=%b",operation,in1,in2,out);
//initial #10 $stop;
endmodule
我給模擬輸出被連接作爲圖像。
爲什麼輸出未定義(X狀態)? 我在做什麼錯?
在'test_projectALU'中,將''''''從'reg'改成''wire'。 – Greg
注意:'!in1;'是一個布爾值而不是in1。 '〜in1'是in1的按位倒數,可能是你在這裏的意思。 – Morgan