我在verilog中有一個8位的ALU單元,可以添加,反轉等。這個單元被測試並正確執行。當我結合其中4個做出更大的ALU時,除了當我選擇加法運算時,每個輸出都是正確的,它出現爲 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx01010101
,基本上第一個alu完成工作,然後第二個輸出是xxxxxxxx
,第三個第四。這真是令人沮喪!使用創建的ALU做出更大的一個
8位模塊(這將是很好的點,如果這種模式是一種行爲或結構模型我去的前!)
module alu_8bit(
output reg [7:0] out,
output reg cout,g,e,
input [7:0] A,B,
input cin,
input [2:0] S
);
//used functions
parameter BUF_A = 3'b000;
parameter NOT_A = 3'b001;
parameter ADD = 3'b010;
parameter OR = 3'b011;
parameter AND = 3'b100;
parameter NOT_B = 3'b101;
parameter BUF_B = 3'b110;
parameter LOW = 3'b111;
always @(A or B or S) begin
//Comparator
g = A>B;
e = A==B;
//Other selective functions
case(S)
BUF_A: out = A;
NOT_A: out = ~A;
ADD: {cout,out} = A+B+cin;
OR: out = A | B;
AND: out = A & B;
NOT_B: out = ~B;
BUF_B: out = B;
LOW: out = {8{1'b0}};
endcase
end
endmodule
這裏是大的代碼:
module alu_32bit(
output [31:0] out,
output cout,g,e,
input [31:0] A,B,
input cin,
input [2:0] S
);
wire e1,e2,e3,e4;
wire g1,g2,g3,g4;
alu_8bit ALU1(out[7:0],cin2,g1,e1,A[7:0],B[7:0],cin,S);
alu_8bit ALU2(out[15:8],cin3,g2,e2,A[15:8],B[15:8],cin2,S);
alu_8bit ALU3(out[23:16],cin4,g3,e3,A[23:16],B[23:16],cin3,S);
alu_8bit ALU4(out[31:24],cout,g4,e4,A[31:24],B[31:24],cin4,S);
assign g = g4 | (e4 & g3) |(e4 & e3 & g2) | (e4& e3 & e2 & g1);
assign e = e4 & e3 & e2 & e1;
endmodule
任何人都可以幫忙嗎?!如果您需要更多信息,請告訴我。
編輯:
波形PIC清楚地輸入進來正確的,但產量不
數據流圖顯示,ALU1輸出就好了
您是否檢查過從ALU1(加法器)執行的不是X? – Morgan 2013-04-28 13:29:52
是的進位是零和輸入到下一個是正確的你想我把8位的不滿足? – 2013-04-28 14:05:10
8位ALU可能很有用,ALU2波形的屏幕截圖也可能有用。 – Morgan 2013-04-29 06:37:54