Range constants?

T

Tim Hubberstey

It is often necessary to extract portions of a vector using a slice.
Whenever I do this, I use constants for maintainability. I have been
using what I refer to as "range constants" where I define a vector
constant that I don't intend to use directly and then use the 'range
attribute on it to define a slice:
 
M

Mike Treseler

Tim said:
constant SomeField : std_logic_vector(21 downto 15)
:= (others => 'X');
out_vec <= source_vec(SomeField'range);
While this works quite well, it seems somewhat messy. Is there a cleaner
way to do this?

That does the job.
I might declare and use
an array or record type to do the same thing.

-- Mike Treseler
 
J

Jonathan Bromley

[...]
-- define a "range constant" in a package
constant SomeField : std_logic_vector(21 downto 15)
:= (others => 'X');

Subtypes?

subtype SomeFieldRange is natural range 21 downto 15;
-----------
out_vec <= source_vec(SomeFieldRange);

Make sure your subtype has the same direction (to/downto)
as the subscripts of source_vec.

Cheers
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:[email protected]
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top