Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Question - aggregates..

Reply
Thread Tools

Question - aggregates..

 
 
Kot
Guest
Posts: n/a
 
      09-12-2003
-- incr8.vhd

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity incr8 is
port (
a : in std_logic_vector(7 downto 0);
cin : in std_logic;
dout : out std_logic_vector(7 downto 0);
cout : out std_logic
);
end entity incr8;

architecture a1 of incr8 is
signal sum : std_logic_vector(8 downto 0);
begin
-- sum <= ('0' & a) + ( 8 downto 1 => '0', 0 => cin ) ;
-- above line does not work. why?
sum <= ( '0' & a ) + ( "00000000" & cin ) ;
cout <= sum(;
dout <= sum(7 downto 0);
end architecture a1;

-- tool used is Synplicity's Synplify
 
Reply With Quote
 
 
 
 
Kot
Guest
Posts: n/a
 
      09-15-2003
Hi Tim,
I tried these two ways but they both don't work:

sum <= ('0' & a) + ( 0 => cin, others => '0' ) ;
Error : aggregate with others must be in a constrained context

sum <= ('0' & a) + ( ( 0 => cin ), ( others => '0' ) ) ;
Error : Can't convert expression to type std_logic
Error : Can't convert expression to type std_logic
(2 identical errors on the same line)

On the other hand, I get no error for following code (original
code that had problem) but the result is simply not what I expected :
sum <= ('0' & a) + ( 8 downto 1 => '0', 0 => cin ) ;

I can go around the problem but I believed it should work this way
either. If there's something wrong with the code, I'd like know
what exactly is wrong to understand better VHDL standard.

Jihwan Song
 
Reply With Quote
 
 
 
 
Egbert Molenkamp
Guest
Posts: n/a
 
      09-15-2003
sum <= ('0' & a) + ( 0 => cin, others => '0' ) ;
is not correct since what are the others? Remember that it is not required
for the addition operator that the left and the right operand has the same
length!

Here are some solution that will work (I hope)

sum <= ('0' & a) + ( '0' & cin ) ;
Notice that in this example both operands do indeed not have the same
length.
Operand a, the longest vector, is extended with a zero. This results in an
output with carry.
The cin is only concatenated with '0'. The function "+" will automatically
extend the shortest
vector to the required length!! (You don't have to make that explicit).

But you tried that: sum <= ('0' & a) + ( 8 downto 1 => '0', 0 => cin ) ;
Although it is correct VHDL and will also synthesize ( correctly ) the
result was surprising to you.
Remember that is a vector is declared that has NO explicit range the vector
has a "to-direction".
This means that ( 8 downto 1 => '0', 0 => cin ) will result in a vector "0
to 8" with the pattern
cin&"00000000". So the cin is on the left (and not on the right).

Try: sum <= ('0' & a) + ( 0 to 7 => '0', 8 => cin ) ;
This will work.

Another way to solve if you like to write down the length of the vector
explict is:
sum <= ('0' & a) + ((a'range=>'0') & cin) ;

Notice that a is vector (7 downto 0). So ((a'range=>'0') will result is
00000000, and on the right it is concatenated with cin.

But I prefer the first short solution :
sum <= ('0' & a) + ( '0' & cin ) ;

Egbert Molenkamp


"Kot" <> schreef in bericht
news: om...
> Hi Tim,
> I tried these two ways but they both don't work:
>
> sum <= ('0' & a) + ( 0 => cin, others => '0' ) ;
> Error : aggregate with others must be in a constrained context
>
> sum <= ('0' & a) + ( ( 0 => cin ), ( others => '0' ) ) ;
> Error : Can't convert expression to type std_logic
> Error : Can't convert expression to type std_logic
> (2 identical errors on the same line)
>
> On the other hand, I get no error for following code (original
> code that had problem) but the result is simply not what I expected :
> sum <= ('0' & a) + ( 8 downto 1 => '0', 0 => cin ) ;
>
> I can go around the problem but I believed it should work this way
> either. If there's something wrong with the code, I'd like know
> what exactly is wrong to understand better VHDL standard.
>
> Jihwan Song



 
Reply With Quote
 
FE
Guest
Posts: n/a
 
      09-15-2003
> sum <= ('0' & a) + ( '0' & cin ) ;
Great solution Egbert but you could just write:
sum <= ('0' & a) + cin;
because in ieee.std_logic_unsigned (the library used by Kot) the operation
std_logic_vector + std_logic is defined.

Kot,
ieee.std_logic_unsigned is not an ieee library (it's a synopsys library) and
you should use ieee.numeric_std.

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

architecture a1 of incr8 is
signal sum : unsigned(8 downto 0);
begin
sum <= unsigned('0' & a) + ('0' & cin); -- with Egbert's solution ( '0' &
cin)
cout <= sum(;
dout <= std_logic_vector(sum(7 downto 0));
end architecture a1;

regards
fe




 
Reply With Quote
 
Kot
Guest
Posts: n/a
 
      09-16-2003
Thank you very much Egbert, fe!
Both of your answeres were very helpful.

Jihwan Song
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57