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

Register Vector

Verilog Arrays

Verilog vectors get realized into flops that match the size of the variable.

Open in IDE
Related tutorial:
design.v
module des (    input           clk,
                input           rstn,
                input           wr,
                input           sel,
                input [3:0]     wdata,
                output [3:0]    rdata);

	reg [3:0] register;

	always @ (posedge clk) begin
        if (!rstn)
            register <= 0;
        else begin
            if (sel & wr)
            register <= wdata;
            else
            register <= register;
        end
	end

	assign rdata = (sel & ~wr) ? register : 0;
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.