12.0 System Tasks and Functions
EDA tool vendors and tool users may define tasks and functions specific to their tool, such as text output or waveform displays.
System tasks and functions begin with the $ (dollar sign). Users may define additional built-in tasks and functions using the Verilog Programming Language Interface (PLI). A few of the most common system tasks and functions are listed in this section.
Text Formatting Codes
%b
%o
%d
%h
%e
%f
%tbinary values
octal values
decimal values
hex values
real values-exponential
real values-decimal
formatted time values%s
%m
\t
\n
\"
\\
%%character strings
hierarchical names
print a tab
print a newline
print a quote
print a backslash
print a percent signA zero in format codes (e.g.: %0d) displays the value using the
minimum field width required. The %e and %f may specify the
field width for both sides of the decimal point (e.g.: %5.2f)
$monitor("text_with_format_specifiers",signal,signal,...);
- Invokes a background process that continuously monitors the signals listed, and prints the formatted message whenever one of the signals changes. A newline is automatically added to the text printed.
$display("text_with_format_specifiers",signal,signal,...);
- Prints the formatted message once when the statement is executed during simulation. A newline is automatically added to the text printed.
$write("text_with_format_specifiers",signal,signal,...);
- Like $display statement, except that no newline is added.
$strobe("text_with_format_specifiers",signal,signal,...);
- Like the $display statement, except that the printing of the text is delayed until all simulation events in the current time step have executed.
- mcd
=$fopen("file_name");
- A function that opens a disk file for writing, and returns a 32-bit integer multi-channel-descriptor (mcd) pointer to the file.
$fclose(mcd);
- A function that closes a disk file that was opened by $fopen.
$monitor(mcd,"text_with_format_specifiers",signal,signal,...);$display(mcd,"text_with_format_specifiers",signal,signal,...);$write(mcd,"text_with_format_specifiers",signal,signal,...);$strobe(mcd,"text_with_format_specifiers",signal,signal,...);
- Variations of the text display tasks that write to files which have been opened with $fopen.
$time
- Returns the current simulation time as a 64-bit integer.
$stime
- Returns the lower 32-bits of simulation time as an integer.
$realtime
- Returns the current simulation time as a real number.
$timeformat(unit,precision,"suffix",min_field_width);
- Controls the format used by the %t text format specifier.
- unit is the base that time is to be displayed in, from 0 to -15
- precision is the number of decimal points to display.
- suffix is a string appended to the time, such as " ns".
- min_field_width is the minimum number of characters that will be displayed.
0 = 1 sec -1 = 100 ms -2 = 10 ms -3 = 1 ms-4 = 100 us -5 = 10 us -6 = 1 us-7 = 100 ns -8 = 10 ns -9 = 1 ns-10 = 100 ps -11 = 10 ps -12 = 1 ps-13 = 100 fs -14 = 10 fs -15 = 1 fsExample:
$timeformat(-9, 2, " ns", 10);
$printtimescale(module_hierarchical_name);
- Prints the time scale of the specified module, or the scope from which it is called if no module is specified.
$random(seed);
- Returns a random 32-bit signed integer.
$readmemb("file_name",register_array,start,end);$readmemh("file_name",register_array,start,end);
- Opens a file for reading, and loads the contents into a register memory array. The file must be an ASCII file with values represented in binary ($readmemb) or hex ($readmemh). The start and end address values are optional.
$finish;
- Finishes a simulation and exits the simulation process.
$stop;
- Halts a simulation and enters an interactive debug mode.