a question regarding paramters to the tasks

A

Amir

Guest
Hi,
is there a way where I can in do in Verilog such in the following
psuedo-code example?:

task hello;
input a;
input b;

if (be "not-defined")
then random(b);

...

endtask

thanks
-Amir
 
On Tue, 12 May 2009 00:08:13 -0700 (PDT), Amir wrote:

is there a way where I can in do in Verilog such in the following
psuedo-code example?:

task hello;
input a;
input b;
Probably best to talk about task "arguments" in Verilog;
"parameter" means something very different.

if (be "not-defined")
then random(b);
I guess you mean
if the caller did not supply a value for argument "b",
then give it my custom random value
??

The answer in Verilog is "no". In SystemVerilog you can
give tasks default arguments:

task hello(input a, input b = 1'bx);

and now, if the user calls hello(1), your task
will effectively see hello(1, 1'bx). You can
then test for the default value inside the task.

HTH
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
A simpler solution, if all you wanted to do was randomize an
unspecified input would be

task hello(input int A, B=$random);

....

endtask

On May 12, 12:19 am, Jonathan Bromley <jonathan.brom...@MYCOMPANY.com>
wrote:
On Tue, 12 May 2009 00:08:13 -0700 (PDT), Amir wrote:
is there a way where I can in do in Verilog such in the following
psuedo-code example?:

task hello;
 input a;
 input b;

Probably best to talk about task "arguments" in Verilog;
"parameter" means something very different.

if (be "not-defined")
then random(b);

I guess you mean
  if the caller did not supply a value for argument "b",
  then give it my custom random value
??

The answer in Verilog is "no".  In SystemVerilog you can
give tasks default arguments:

  task hello(input a, input b = 1'bx);

and now, if the user calls hello(1), your task
will effectively see hello(1, 1'bx).  You can
then test for the default value inside the task.
 

Welcome to EDABoard.com

Sponsor

Back
Top