1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
module dffn(input CLK, D, output reg Q, output QN); always @(negedge CLK) Q <= D; assign QN = ~Q; endmodule module dffsr(input CLK, D, CLEAR, PRESET, output reg Q, output QN); always @(posedge CLK, posedge CLEAR, posedge PRESET) if (CLEAR) Q <= 0; else if (PRESET) Q <= 1; else Q <= D; assign QN = ~Q; endmodule