现在我打算按照下面的方式实现时钟门控。 但我不明白为什么以及如何处理De信号?我是否需要在顺序总是块中的else语句?
module ClockGating(
input wire rst_n,
input wire clk,
input wire De,
input wire InReg,
output reg OutReg
);
always @(posedge clk or negedge rst_n)
begin
if (!rst_n) begin
OutReg <= 0;
end
else begin
if (De) begin
OutReg <= InReg;
end
else
OutReg <= OutReg;
end
end
endmodule
但我想知道如果我没有使用else语句那么会发生什么? 我可以使用没有else语句吗?
module ClockGating(
input wire rst_n,
input wire clk,
input wire De,
input wire InReg,
output reg OutReg
);
always @(posedge clk or negedge rst_n)
begin
if (!rst_n) begin
OutReg <= 0;
end
else begin
if (De) begin
OutReg <= InReg;
end
end
endmodule
这是我的学生经常遇到的问题。 –
是的,您可以删除'else'语句,并且'OutReg'将保留它的值,因为它是一个'reg' –