Hello good people of google,
I am trying to assign a certain part of a SLV(std_logic_vector) to another shorter SLV, and forcing the remaining to be '0'.
Ex, lets assign the middle 5 bits of big_word to small word.
--
Signal big_word :std_logic_vector(10 - 1 downto 0) := (others => '0');
Signal small_word :std_logic_vector(5 - 1 downto 0) := (others => '0');
...
Begin
-- I can of course use this, but this is not very elegant for large SLVs Big_word <= "000" & small_word & "00";
--I would like to do something more like:
Big_word <= (7 -1 downto 2 => small_word, others => '0');
--The tool I am using (vivado 2018.3) complains about small_word not being of type std_ulogic. Well the word is larger than 1 bit, so that is an issue.
Rick,
Thanks for the input.
I have done this in a process before with the method you mentioned.
Do you know of a 1 or 2 lines solution when NOT in a process?
CT
Rick,say? I'll have to do some reading up on this.
I am using vivado 2018.3. I believe it is defaulted to VHDL 87. I will look into upgrading to 08. I'm still green here, and wanted to write my design in a way that could be used in as many places as possible. VHDL 08 is supported most everywhere you
That link is a great resource, I will keep that in mind.
Thanks again
CT
Rick,say? I'll have to do some reading up on this.
I am using vivado 2018.3. I believe it is defaulted to VHDL 87. I will look into upgrading to 08. I'm still green here, and wanted to write my design in a way that could be used in as many places as possible. VHDL 08 is supported most everywhere you
That link is a great resource, I will keep that in mind.
Thanks again
CT
Unfortunately even with vhdl 08 the solution:
Big_word <= (7 -1 downto 2 => small_word, others => '0');
Does not work. When this is used, the whole big_word signal is assigned to '0'.
I will keep trying with vhdl 08 and report back once ive found a solution
On 3/11/20 8:01 AM, CT wrote:
Unfortunately even with vhdl 08 the solution:
Big_word <= (7 -1 downto 2 => small_word, others => '0');
Does not work. When this is used, the whole big_word signal is assigned to '0'.
I will keep trying with vhdl 08 and report back once ive found a solution
Slices like that only operate with single bit values.
You can write it as a function or procedure though. That way you can do sequential assignment.
function pad_right(val:std_logic_vector, len:integer) return std_logic_vector is
variable x : std_logic_vector(len-1 downto 0) := (others => '0');
begin
x(len-1 downto len-(val'length)) := val;
return x;
end function pad_right;
big_word <= pad_right(small_word, big_word'length);
On Wednesday, March 11, 2020 at 12:27:19 PM UTC-4, Rob Gaddi wrote:20slice%20in%20an%20array%20aggregate&f=false
On 3/11/20 8:01 AM, CT wrote:
Unfortunately even with vhdl 08 the solution:
Big_word <= (7 -1 downto 2 => small_word, others => '0');
Does not work. When this is used, the whole big_word signal is assigned to '0'.
I will keep trying with vhdl 08 and report back once ive found a solution >>>
Slices like that only operate with single bit values.
Can you explain what you mean by "slices like that"??? Like what?
Here is a hard to find example of exactly the slice aggregate operation the OP is talking about.
https://books.google.com/books?id=ETxLguPMEY0C&pg=PA166&lpg=PA166&dq=VHDL+slice+in+an+array+aggregate&source=bl&ots=q9wZSq_TB_&sig=ACfU3U3hcaEpAlXpDSw93ilUOjLnmPUIHg&hl=en&sa=X&ved=2ahUKEwiMm9DE75LoAhX1mXIEHXgcDKEQ6AEwBnoECAgQAQ#v=onepage&q=VHDL%
Scroll down to p167.
You can write it as a function or procedure though. That way you can do
sequential assignment.
function pad_right(val:std_logic_vector, len:integer) return std_logic_vector is
variable x : std_logic_vector(len-1 downto 0) := (others => '0');
begin
x(len-1 downto len-(val'length)) := val;
return x;
end function pad_right;
big_word <= pad_right(small_word, big_word'length);
The function suggestion might be the best to get past the issue and get the work done.
Thanks guys,task (assigning a part of a slv to another slv, the rest '0')?
Youve helped me find a solution that fits my very specific requirements. Seeing as that you guys are definitely more experienced than I, and it dosen't seem like you use the method I am trying to do very frequently, what methods do you prefer for this
Using the function Rob used? Or always making this sort of assignment in a combinational process?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 185 |
Nodes: | 16 (1 / 15) |
Uptime: | 84:08:55 |
Calls: | 3,750 |
Files: | 11,172 |
Messages: | 3,461,943 |