我在verilog中有一个8位的ALU单元,可以做加法,反转等。这个单元经过测试,运行正常。当我将其中的4个组合成一个更大的算术逻辑单元时,每个输出都是正确的,除了当我选择加法操作时,它是xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx01010101,基本上第一个ALU做了正确的工作,然后第二个alu的输出是xxxxxxxx,第三个和第四个也是。这真是令人沮丧!!
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 有人能帮上忙吗?!如果你需要更多的信息,请告诉我。
编辑:
清晰的波形图片输入正确,但输出不正确

数据流程图显示ALU1输出正常

发布于 2013-04-29 15:44:24
你的算术逻辑单元主要部分的敏感度列表不包括cin。
https://stackoverflow.com/questions/16262058
复制相似问题