Professional Documents
Culture Documents
Verilog allows you to read or write files to load memories, apply stimulus, and control simulation read stimulus files to apply patterns to the inputs of a model read a file of expected values for comparison with you model read a script of commands to drive a simulation
Open & Close Read operation Write operation File status File position
The le open function, $fopen(), returns a value whose bits indicate a corresponding channel available for writing. $fopen() opens the le specied as an argument and returns the next available 32-bit multichannel descriptor, which is unique for the le. If the le could not be found or opened for writing, it returns 0.
The multichannel descriptor can be considered to be a set of 32 ags, where each ag represents a single output channel. The least signicant bit (bit 0) always represents standard output, also called channel 0, while the other bits represent channels which have been opened by $fopen() Syntax mcd = $fopen(type) (filename); where multi-channel descriptor is an integer
The le close function, $fclose(), closes the specied channel in the multichannel descriptor. Syntax $fclose(multi_channel_descriptor); where multi-channel_descriptor is an integer value representing the channel(s) to be closed
The le display function, $fdisplay(), writes data to the channel(s) specied in the multichannel descriptor. Syntax $fdisplay(mcd [, list_of_arguments ]); list_of_arguments is an optional, comma separated list of quoted strings or expressions
module fopenclose(); integer mcd,number; initial begin mcd = $fopen("temp.txt"); // mcd = multi_channel_descriptor repeat(7) begin number = $random; $fdisplay(mcd, "Number is ", number); end $fclose(mcd); end endmodule RESULT Number is Number is Number is Number is Number is Number is Number is 303379748 -1064739199 -2071669239 -1309649309 112818957 1189058957 -1295874971
$fscanf(integer, format, args); %b Binary data %o Octal data %h, %x Hexadecimal data %d Decimal data %c Character %s String
integer file, position; position = $ftell(file);The function $ftell returns the position in the file . If there is an error, it returns a -1. integer pos = $fseek(f_handle, offset, operation); 0: from beginning 1: from current 2: from end
integer file; reg error; error = $ferror(file);The function $ferror returns the error status of a file. If an error has occurred while reading from a file, $ferror returns a non-zero value, else 0. The error value is returned once, then reset to 0.
integer file, char; char = $fgetc(file); The function $fgetc reads a single character from the specified file and returns it. If the end-of-file is reached, $fgetc returns EOF
integer stream, r, char; r = $fputc(stream, char); The function $fputc writes a single character to the specified file. It returns EOF if there was an error, 0 otherwise.
THANK YOU