Opening a file
keywords : $open Syntax: <file_handle> = $fopen("<file_name"); The default output of a Verilog program normally goes to the standard ouput but this can be redirected to a file. The file handle mentioned in the syntax above is a 32 bit descriptor. Out of the 32 bits only one bit is high, for the standard output has its least significant bit set. Everytime a call is made to $fopen a new handle is created with the next bit to the left is set to high. So the first call would set the 2nd least significant bit, the second call would set the bit next to that, and so on. Below is an example showing how to open files.
i n t e g e rh a n d l e A ,h a n d l e B ;/ /a ni n t e g e rh a s3 2b i t ss oi sp e r f e c t / /f o rt h i su s a g e i n i t i a lb e g i n h a n d l e A=$ f o p e n ( " m y f i l e . o u t ) ; / /h a n d l e A=0 0 0 0 _ 0 0 0 0 _ 0 0 0 0 _ 0 0 0 0 _ 0 0 0 0 _ 0 0 0 0 _ 0 0 0 0 _ 0 0 1 0 h a n d l e B=$ f o p e n ( " a n o t h e r f i l e . o u t " ) ; / /h a n d l e B=0 0 0 0 _ 0 0 0 0 _ 0 0 0 0 _ 0 0 0 0 _ 0 0 0 0 _ 0 0 0 0 _ 0 0 0 0 _ 0 1 0 0 e n d
Now we can write to any of the opened files. There is a maximum of 31 files open. next contents