Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

implementation of stdin and $feof in icarus verilog

599 views
Skip to first unread message

Jason Zheng

unread,
Apr 22, 2010, 11:35:08 AM4/22/10
to
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?

Stephen Williams

unread,
Apr 22, 2010, 1:18:09 PM4/22/10
to
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."

Jason Zheng

unread,
Apr 22, 2010, 2:11:00 PM4/22/10
to
On Thu, 22 Apr 2010 10:18:09 -0700
Stephen Williams <spam...@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!


0 new messages