SystemVerilog Enhanced Data Types and Expressions
SystemVerilog Enhanced Data Types and Expressions
by Swaroop D
4MH21EC104
Constants
• In SystemVerilog, parameters can be declared at the $root level so they can
be global. This approach can replace many Verilog macros that were just
being used as constants.
• You can use a typedef to replace those clunky macros. The next choice is a
parameter. A Verilog parameter was loosely typed and was limited in scope
to a single module.
• SystemVerilog also supports the const modifier that allows you to make a
variable that can be initialized in the declaration but not written by
procedural code.
EXAMPLE : Declaring a const variable
intial begin
const byte colon = “:”;
…
end
Strings
• The SystemVerilog string type holds variable-length strings. An individual
character is of type byte. The elements of a string of length N are
numbered 0 to N-1.
• Note that, unlike C, there is no null character at the end of a string, and
any attempt to use the character “\0” is ignored.
• Strings use dynamic memory allocation, so you do not have to worry about
running out of space to store the string
Example Program
string s;
initial begin
s="SystemVerilog";
$display(s.getc(0)); // Display: 83 (‘S’)
$display (s.toupper()); //
Display:SYSTEMVERILOG
s ={s, "3.1b“}; //
"SystemVerilog3.1b“
s.putc(s.len (-1, "a"); // change b-> a
$display(s.substr(2, 5));// Display: stem
// Create temporary string, note format
my_log($psprintf("%s %5d", s, 42));
end