解析:先觀察電路情況,兩個D觸發器,一個與門,先將第一個D觸發器寫出來,命名reg變數為data_in_reg,顯然是將輸入訊號data_in寄存一位,最後data_out訊號,是當前輸入訊號與寄存訊號非的與。
`timescale 1ns/1ns
module RTL(
input clk,
input rst_n,
input data_in,
output reg data_out
);
reg data_in_reg;
always@(posedge clk or negedge rst_n)
if(!rst_n)
data_in_reg <= 1'b0;
else
data_in_reg <= data_in;
always@(posedge clk or negedge rst_n)
if(!rst_n)
data_out <= 1'b0;
else
data_out <= data_in & ~data_in_reg;
endmodule