// Exercise B4: a D flip-flop with an asynchronous reset.
//
// Generic version that matches schematic 1: one D flip-flop and a NOT gate
// for the inverted output, not tied to any chip.  Synthesizable.

module d_flip_flop
(
    input  logic clk,
    input  logic rst,  // 1 = Q goes to 0 at once, like RESET of the 4013
    input  logic d,

    output logic q,    // D as it was at the last rising edge of clk
    output logic q_n   // NOT Q
);

    always_ff @ (posedge clk or posedge rst)
        if (rst)
            q <= 1'b0;
        else
            q <= d;

    assign q_n = ~ q;

endmodule
