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

Constraint 'inside': Practical Example

SystemVerilog Constraints

Runnable example from the SystemVerilog Constraint 'inside' tutorial (Practical Example)

Open in IDE
testbench.sv
class Data;
	rand bit [15:0] 	m_addr;

	constraint c_addr 	{ m_addr inside {[16'h5000:16'h5fff]}; }
endclass

module tb;
	initial begin
		Data data = new();
		repeat (5) begin
			data.randomize();
			$display ("addr = 0x%0h", data.m_addr);
		end
	end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.