Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

use of for loop in vhdl

Status
Not open for further replies.

jagansai

Newbie level 2
Joined
Oct 22, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
21
can you tell the diff between this two assignments


Code VHDL - [expand]
1
2
3
if( rising_edge(clk))then
d_in(width-1 downto 0)<= d_out(width-1 downto 0);
end if;




Code VHDL - [expand]
1
2
3
4
5
if(rising_edge(clk)) then
for i in 0 to width-1 loop
d_in(i) <= d_out;
end loop;
end if;

 

assuming d_out is an array like the first example, then the second code will fail a syntax check because you're trying to assign a single element with an array.
 

can you tell the diff between this two assignments
Yes I can. The first assignment will compile correctly, the second will not compile without an error.

Kevin Jennings
 

This was probably a homework question. You two just gave them the answer.
 

can you tell the diff between this two assignments
Are you serious??
It's obvious - the 1st snippet is 3 lines long while the 2nd snippet has 5 lines in it...
 

Code:
-- vector assign is done by left/right positioning --independent of the specific index/direction declared for each.
yVector <= xVector;

-- vs

-- explicitly done by index
for i in xVector'range loop
  yVector(i) <= xVector(i);
end loop;

-- if you have:
signal xVector : std_logic_vector(1 to 4);
signal yVector : std_logic_vector(3 downto 0);
-- the first case will work, the second will not.
 

can you tell the diff between this two assignments


Code VHDL - [expand]
1
2
3
if( rising_edge(clk))then
d_in(width-1 downto 0)<= d_out(width-1 downto 0);
end if;




Code VHDL - [expand]
1
2
3
4
5
if(rising_edge(clk)) then
for i in 0 to width-1 loop
d_in(i) <= d_out(i);
end loop;
end if;



sorry i entered wrongly. Now,i enter correctly.

my question is what is difference between direct assignment and for loop assignment. Both doing same fuction only. Then what is the use of for loop. please justify the answer.
 
Last edited by a moderator:

The code here is functionality equivalent. So what code you use here is a question of style.
 

In this specific case that is correct. If you see the first example, you could rewrite it as the second. However, If you saw the second, you would need to check the definitions to ensure you could rewrite it as the first. my post #6 shows an example. This comes up more often if you write functions.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top