
The read statement is used to read a vector of values from an external file and assign the values to a set of variables or nets. The first operand of a read statement must be a number (or an expression) that specifies the file to be read. The following is an example of a read statement.
read 0,inputa,inputb,xyz
Windows Format:
read @FileName,inputa,inputb,xyz
Or:
read |DLLName,inputa,inputb,xyz
In the second format, the first character is the vertical mark, the shift of the back-slash.
Each vector consists of a number of values separated by commas and terminated by an end of line character. If the vector contains more values than there are variables (or nets) on the read statement, the extra values are discarded. If there are fewer values than variable names (or net names) the extra variables (or nets) will be assigned the value zero. The values must be specified in hexadecimal without the leading 0x or 0X.
The file number must be (or evaluate to) a number between zero and ten inclusive. A file number of zero causes the standard input to be read. (Recall that a set of FHDL specifications compiles into a UNIX program. The zero file refers to the standard input of that program, which defaults to the terminal.) File numbers between one and ten refer to the arguments of the command used to invoke the simulator. A file number of 1 causes the first argument of the command to be treated as a file name, and the program reads the input vector from that file.
If specifying input values in hexadecimal is inconvenient, the "readd" statement can be used to read decimal, octal, or hexadecimal data. The format of the "readd" statement is identical to that of the "read" statement. When the "readd" statement is used, input values are assumed to be in decimal if they begin with a non-zero digit, octal if they begin with zero, and hexadecimal if they begin with the characters 0x or 0X.
The "get" command can be used to abbreviate reads from the standard input. The following two commands are equivalent.
read 0,inputa,inputb,xyz
get inputa,inputb,xyz
The windows version of FHDL no longer has a get command.
The command "getd" can be used to read decimal, octal, and hexadecimal data from the standard input. Its format is identical to that of the "get" statement.
The expression "eof(<file number>)" can be used to test a file for end-of-file. The expression eof(0) returns 1 if file zero (stdin) is at end of file, and zero otherwise.