For certain routine operations Verilog provides system tasks. all such tasks are in the form $keyword. In this section we will discuss writing to output, monitoring a simulation and ending a simulation.
Keyword: $display, $displayb, $displayh, $displayo, $write, $writeb, $writeh, $writeo.
The most useful of these is $display.This can be used for displaying strings, expression or values of variables. Here are some examples of usage.
$display("Hello Dr Blair");
--- output: Hello Dr Blair
$display($time) // current simulation time.
--- output: 460
counter = 4'b10;
$display(" The count is %b", counter);
--- output: The count is 0010
The formatting syntax is similar to that of printf in the C programming language. For $display and $display, they are:
-------------------------------------------
| Format Specifications |
-------------------------------------------
| Format | Display |
| -------- | ---------------------------- |
| %d or %D | Decimal |
| %b or %B | Binary |
| %h or %H | Hexadecimal |
| %o or %O | Octal |
| %m or %M | Hierarchical name |
| %t or %T | Time format |
| %e or %E | Real in scientific format |
| %f or %F | Real in decimal formal |
| %g or %G | Real in shorter of above two |
-------------------------------------------
The escape sequence for printing special characters are:
--------------------
| Escape Sequences |
--------------------
| \n | newline |
| \t | tabulate |
| \\ | print \ |
| \" | print " |
| %% | print % |
--------------------
$write is identical to $display except it does not automatically put a newline at the end of its output.
EXERCISE What does $display without any arguments output? What does that tell you about $write?
If the formatting character is omitted, the various commands default as below:
---------------------------
| Default Format Specs |
---------------------------
| Task | Default |
| --------- | ----------- |
| $display | decimal |
| $displayb | binary |
| $displayh | hexadecimal |
| $displayo | octal |
| $write | decimal |
| $writeb | binary |
| $writeh | hexadecimal |
| $writeo | octal |
---------------------------
Thus
$write(5'b01101);
$writeb(" ", 5'b01101);
$writeh(" ", 5'b01101);
$writeo(" ", 5'b01101,"\n");
13 01101 0d 15