Write Verilog for a D-latch
Write Verilog for a D-latch
Model answer
A D-latch is **level-sensitive**: while en = 1 the output follows d (transparent); while en = 0 the output holds its last value. {|c|c|c|}\hline en & d & Q^{+}\\ \hline 0 & X & Q\ (hold)\\ \hline 1 & 0 & 0\\ \hline 1 & 1 & 1\\ \hline verilog module d_latch (input d, en, output reg q); always @(*) if (en) q = d; // no else: the missing branch IS the latch endmodule verilog // with active-low asynchronous reset module d_latch_rst (input d, en, rst_n, output reg q); always @(*) if (!rst_n) q = 1'b0; else if (en) q = d; endmodule Symbol (TikZ):