module T_flip_flop(T,CLK,Q,Clear); input T,CLK,Clear; output Q; xor x(D1,T,Q); assign D = Clear? 0: D1; D_flip_flop d(D,CLK,Q); endmodule module D_flip_flop(D,CLK,Q); input D,CLK; output Q; wire CLK1, Y; not not1 (CLK1,CLK); D_latch D1(D,CLK, Y), D2(Y,CLK1,Q); endmodule module D_latch(D,C,Q); input D,C; output Q; wire x,y,D1,Q1; nand nand1 (x,D, C), nand2 (y,D1,C), nand3 (Q,x,Q1), nand4 (Q1,y,Q); not not1 (D1,D); endmodule module test_D_flip_flop; reg D,C,Clear; wire Q; T_flip_flop D1(D,C,Q,Clear); always #1 C=~C; initial begin $monitor("%d %b %b %b",$time,D,C,Q); C=0; Clear=1; #2 Clear=0; D=0; #8 D=1; #8 $finish; end endmodule