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

How To Define A New Enumerated Data Type?

SystemVerilog Data Types

typedef enum {NO, YES} boolean defines a new type; a variable of it is assigned and printed with .name.

Open in IDE
testbench.sv
module tb;
	// boolean is a new data-type with two valid values: NO and YES
	typedef enum {NO, YES} boolean;       
	
	initial begin
		// Declare a variable of type boolean that can store NO or YES
		boolean  answer;                       
		
		// Assign NO/YES to the enumerated variable
		answer = YES;
		
		// Display string value of the variable
		$display ("answer = %s", answer.name);
	end
endmodule

/*
Simulation Log:
---------------
ncsim> run
answer = YES
ncsim: *W,RNQUIE: Simulation is complete.
ncsim> exit
*/
design.sv
// Code your design here
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.