//DFF code
module dff(q, rst, clk, d);
output q;
input clk,rst;
input d;
reg q;
always @(negedge clk)
if(~rst)
q <= 1'b0;
else
q <= d;
endmodule
//testbench
module tb;
reg clk,rst,d;
wire q;
initial begin
clk = 1'b0;
rst = 1'b1;
d = 1'b0;
#10 rst= 1'b0;
#20 rst =1'b1;
#10 d = 1'b1;
#20 d = 1'b0;
#30 d = 1'b1;
#10 d = 1'b0;
end
always
#5 clk = ~clk;
dff x1(q, rst, clk, d);
endmodule