比较两份代码,看看有什么问题
module top_module (
input clk,
input reset,
input [31:0] in,
output [31:0] out
);
reg [31:0] temp01;
always@(posedge clk)begin
if(reset)
out<=0;
else begin
temp01<=in;
out<=temp01&(~in)|out;
end
end
endmodule
1 module top_module (
2 input clk,
3 input reset,
4 input [31:0] in,
5 output [31:0] out
6 );
7 reg[31:0] in_last;//in's last state
8 always@(posedge clk)//D Flip-Flop
9 in_last <= in;
10 always@(posedge clk)
11 if(reset)
12 out <= '0;
13 else
14 out <= out | in_last & ~in;
15 endmodule
第一份是错的,第二份是对的。
其实根本不是时序的问题。
第一份的逻辑里,如果reset,那么temp01就不会存储上一次in的值。