dff:
module d_ff (
input clk,
input rst_n,
input en,
input d,
output reg q
);
always @ (posedge clk or negedge rst_n)
if (!rst_n)
q <= 0;
else if (en)
q <= d;
endmodule
latch:
module lat(Q, Q‘, D, clk, rst_n); // level-triggered latch behavioral model
input D,clk,rst_n;
output Q, Q';
reg Q;
always @(clk or rst_n or D)
begin
if(!rst_n)
Q=1'b0;
else if(clk)
Q=D;
end
assign Q' = ~Q;
endmodule
本文系http://yuqix.blog.51cto.com/979066/214861博文修改而成。