Opening a file with a reg type

Y

Yottameter

Guest
I'm currently using parameters to open up a file:

$readmemb({ROOT_DIR, LOCAL_DIR, TEST,TEST_SUFFIX}, mem);

If I change TEST to a register declaration:

reg [40*8:0] TEST;//

How can I remove the whitespace at the beginning of the register, so the
concatenation above works? The concatenation results in a lot of
undefined values at the beginning of TEST, ie 40-(length(TEST)). I'm
really trying to 'resize' the register, so I think my question is
impossible to answer.

Seems like I'm missing a concat for strings in verilog.

The reason I'd like to do this is that I'd like to pass in ROOT_DIR,
LOCAL_DIR, TEST and TEST_SUFFIX as command line options using
$value$plusargs as opposed to using parameter modifiers on the command line.

Thanks.
 
On Mon, 16 Jun 2008 14:38:24 -0700, Yottameter <yottameter@yahoo.com>
wrote:

I'm currently using parameters to open up a file:

$readmemb({ROOT_DIR, LOCAL_DIR, TEST,TEST_SUFFIX}, mem);

If I change TEST to a register declaration:

reg [40*8:0] TEST;//

How can I remove the whitespace at the beginning of the register,
First, make your string regs an exact multiple of 8 bits:
reg[40*8:1] TEST;
as it makes them easier to work with - though I don't think
it affects the solution offered below.

Can you use $sformat to get the desired effect? It works for me:

reg [80*8:1] filename;
reg [40*8:1] TEST;
...
$sformat(filename, "%0s%0s%0s%0s",
ROOT_DIR, LOCAL_DIR, TEST, SUFFIX);
$readmemb(filename, mem);

Using %0s as the formatter prunes away any leading nulls.
--
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.
 
Thanks Jonathan, that worked well.

Jonathan Bromley wrote:
On Mon, 16 Jun 2008 14:38:24 -0700, Yottameter <yottameter@yahoo.com
wrote:


I'm currently using parameters to open up a file:

$readmemb({ROOT_DIR, LOCAL_DIR, TEST,TEST_SUFFIX}, mem);

If I change TEST to a register declaration:

reg [40*8:0] TEST;//

How can I remove the whitespace at the beginning of the register,


First, make your string regs an exact multiple of 8 bits:
reg[40*8:1] TEST;
as it makes them easier to work with - though I don't think
it affects the solution offered below.

Can you use $sformat to get the desired effect? It works for me:

reg [80*8:1] filename;
reg [40*8:1] TEST;
...
$sformat(filename, "%0s%0s%0s%0s",
ROOT_DIR, LOCAL_DIR, TEST, SUFFIX);
$readmemb(filename, mem);

Using %0s as the formatter prunes away any leading nulls.
 

Welcome to EDABoard.com

Sponsor

Back
Top