【发布时间】:2021-11-17 18:55:43
【问题描述】:
我正在尝试在 Verilog 中构建一个 32 位 ALU。我在一开始就实现了一个 1 位 ALU。 ALU 应该只有 4 个函数,而不是全部:add、sub、and、or。这是我的代码:
module ALU(
input wire [3:0] OPCode,
input wire Operand1,
input wire Operand2,
input wire cin,
output reg Result,
output reg Cout
);
always@(*)
begin
case(OPCode)
4'b0000: Result = Operand1&Operand2;
4'b0001: Result = Operand1|Operand2;
4'b0010:
begin
Result = cin ^(Operand1 ^ (Operand2 ^ cin));
Cout = ((Operand2 ^ cin) & Operand1) | ((Operand1 ^ (Operand2 ^ cin)) & cin);
end
4'b0110:
begin
Result = cin ^(Operand1 ^ (Operand2 ^ cin));
Cout = ((Operand2 ^ cin) & Operand1) | ((Operand1 ^ (Operand2 ^ cin)) & cin);
end
endcase
end
endmodule
这里的问题是它会生成不必要的 LATCH 门。我已经知道这是因为我没有在case 声明中涵盖所有案例;但是,这些是我唯一的案例。
我应该怎么做才能修复我的case 语句?
【问题讨论】:
标签: verilog