🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.verilog
Article #99

Re: Variable width assignments?

#99
From: W. Scott Cranston
Date: Sat, 26 Sep 1992 23:09
70 lines
2656 bytes
In article <rfall-240992171955@andrich.mv.us.adobe.com>rfall@mv.us.adobe.com (Richard Fall) 
writes:
> 
> Does anyone know if there's an easy way of doing the following
> in Verilog?
> 
>     I would like to be able assign a fixed value (say, zero),
>     declared as a single parameter ("zero") in assignment
>     statements where the variable on the LHS of the statements
>     may be of different bit width.
>     
>     That is, if I have the following:
>     
>         reg [1:0] foo;
>         reg [2:0] foolong;
>         
>     I would like to be able to say:
>      
>          foo = zero;
>          foolong = zero;
>          
>     and have the correct assignment take place.
>      
>     
>     Before you rush to tell me that Verilog already does that
> by zero-extending the RHS side to fit the LHS side, I'll point
> out that I may want to do the same thing with a parameter in
> which zero-extending is not the correct behavior.  For
> example, I may want the value "5555...." to be assigned to
> registers that may be any multiple of 4 bits wide.
> 
>     If there were a "sizeof" operator, this would be easy
> to do by using it in conjunction with repeated concatenation
> to produce the desired effect, but no such operator appears to
> exist.
> 
>     Am I missing something, or is there a clever way to do this?
> 
> 

You could make a max length integer which consists of the specified
integer repeated and assign it to the LHS.  Verilog will truncate to
the correct size.  For instance:

	reg [3:0] foo;
	reg [15:0] foolong;

	parameter rhs = (1E6{4'h5}};
	foo = rhs;
	foolong =  rhs;



foo will be 4'h5 and foolong will be 16'h5555.


Of course, 1E6 is too big, but use whatever you need.

Good Luck,
  Scott Cranston
  Cadence Design Systems




--
+---------^>        "The Spirit of Massachusetts is the Spirit of America"
|        <                    -Massachusetts Division of Tourism
+-------. \   7     "Right..."
         \_\_/                -cranston@cadence.com
Technical Details
Message-ID: <CRANSTON.92Oct9065350@ayn.cadence.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!Cadence.COM!cadence.com!cranston
References: <rfall-240992171955@andrich.mv.us.adobe.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.verilog
Path: arc1-ca.pugleaf.net!sparky!uunet!Cadence.COM!cadence.com!cranston
From: cranston@ayn.cadence.com (W. Scott Cranston)
Subject: Re: Variable width assignments?
In-Reply-To: rfall@mv.us.adobe.com's message of 25 Sep 92 00:19:22 GMT
Message-ID: <CRANSTON.92Oct9065350@ayn.cadence.com>
Followup-To: comp.lang.verilog
Sender: usenet@Cadence.COM (Usenet News)
Nntp-Posting-Host: ayn
Organization: Cadence Design Systems, Lowell MA, United States of America
References: <rfall-240992171955@andrich.mv.us.adobe.com>
Date: Sat, 26 Sep 1992 23:09:50 GMT
Lines: 70