Escolar Documentos
Profissional Documentos
Cultura Documentos
ELEC444/644
Session 3
K. Joseph Hass
Electrical Engineering
Bucknell University
$fopen(filename,[accesstype]);
$fscanf(filehandle,format spec,[value],[value],. . . );
$fdisplay(filehandle,[format spec],[value],[value],. . . );
$fwrite(filehandle,[format spec],[value],[value],. . . );
$fmonitor(filehandle,[format spec],[value],[value],. . . );
$fclose([filehandle]);
Basic Verilog File IO
Opening and Closing Files
integer MyFileHandle;
MyFileHandle = $fopen(”MyFileName”,”MyAccessType”);
$fclose(MyFileHandle);
r e a l MyNumber ;
integer i ;
i = 1;
w h i l e ( i >0) begin
@( posedge C h a n g e I n p u t s ) ;
i=$ f s c a n f ( M y I n p u t F i l e , ”%f ” , MyNumber ) ;
end
%b binary %d decimal
%h hexadecimal %s string
%t time %c character
%m module name %f real
%v strength %e exponential
The $fscanf should return −1 at end-of-file. . . this is broken in Xilinx ISE Version 11. . . use $feof instead.
Basic Verilog File IO
Writing To A Text File
integer MyFileDescriptor ;
r e a l MyNumber ;
always @( posedge O u t p u t S t r o b e )
$ f d i s p l a y ( M y F i l e D e s c r i p t o r , ”%f ” , MyNumber ) ;
parameter STDOUT = 1 ;
i n t e g e r MyMCD; // A m u l t i c h a n n e l d e s c r i p t o r
r e a l MyNumber ;
always @( posedge O u t p u t S t r o b e ) ;
$ f d i s p l a y ( (MyMCD | STDOUT) , ”%f ” , MyNumber ) ;
end
initial
$monitor ( ”A= %h t i m e= %t ” , MySig , $ r e a l t i m e ) ;