implementation of stdin and $feof in icarus verilog

J

Jason Zheng

Guest
Hi,

The Verilog 2001 reference defines stdin, stdout, and stderr as
pre-opened file descriptors (0x80000001- 0x80000003). However, when I
tried to use stdin in Icarus, the stdin does not seem to be opened.

In addition, although I haven't seen it in the Verilog 2001 reference,
some examples on the web have used "$feof" to test the EOF for a file
descriptor. Icarus doesn't reject it as a syntax error, but when I
tried to use $feof on stdin, it seems to think that stdin has not
reached EOF even though $fget returns FFFFFFFF.

Here's my test code:

`timescale 1ns / 100ps

module mytb;

parameter clk_per = 10;
parameter STDIN = 32'h8000_0001;

reg CLK;
integer tmp;

initial
begin
CLK = 0;
forever
#(clk_per/2) CLK = ~CLK;
end

always @ (negedge CLK)
if (!$feof(STDIN))
begin
tmp = $fgetc(STDIN);
$display("%x",tmp);
end
else
$finish;

endmodule

Any thoughts, Steve?
 
Jason Zheng wrote:
Hi,

The Verilog 2001 reference defines stdin, stdout, and stderr as
pre-opened file descriptors (0x80000001- 0x80000003). However, when I
tried to use stdin in Icarus, the stdin does not seem to be opened.
You've got the wrong numbers there. The pre-opened descriptors
are 0x80000000 - 0x80000002.

In addition, although I haven't seen it in the Verilog 2001 reference,
some examples on the web have used "$feof" to test the EOF for a file
descriptor. Icarus doesn't reject it as a syntax error, but when I
tried to use $feof on stdin, it seems to think that stdin has not
reached EOF even though $fget returns FFFFFFFF.
It works in Icarus Verilog. I fixed your sample program and it
runs fine.

parameter clk_per = 10;
parameter STDIN = 32'h8000_0001;
There's your problem. Standard input is 32'h8000_0000. The value
you have there is for standard output.

--
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
 
On Thu, 22 Apr 2010 10:18:09 -0700
Stephen Williams <spamtrap@icarus.com> wrote:
parameter clk_per = 10;
parameter STDIN = 32'h8000_0001;

There's your problem. Standard input is 32'h8000_0000. The value
you have there is for standard output.
Doh! Thanks!
 

Welcome to EDABoard.com

Sponsor

Back
Top