Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

DFF Module Example

Verilog Modules

Example of a module with input and output ports

Open in IDE
Related tutorial:
design.v
// Module called "dff" has 3 inputs and 1 output port
module dff ( 	input 		d,       // Data input
				input 		clk,     // Clock signal
				input 		rstn,    // Active-low asynchronous reset
				output reg	q);      // Registered output (must be 'reg' for sequential logic)

	// Sequential logic block: executes on every positive clock edge
	always @ (posedge clk) begin
		if (!rstn)             // Reset condition (active-low: rstn=0 triggers reset)
			q <= 0;              // Non-blocking assignment: reset output to 0
		else
			q <= d;              // Non-blocking assignment: capture input data
	end
endmodule
testbench.v
// Enter testbench code
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.