You are right but this work just when "a" is possitive. suppose that a is
1000-0001(-127) aa would be 0-1000-0001 while we expected it to be
1-1000-0001.
when i use arith_std_logic and conv_signed(a,9)it works, but i nees to use
numeric.
Any idea?
I think you need to rethink your problem.
If a is unsigned, then it is never negative and
the following is correct:
signal a :unsigned(7 downto 0);
aa <= signed('0' & a);
However, the following is not correct when a is a large
positive number and b is a large negative number.
signal a : unsigned(7 downto 0);
signal b,c : signed(8 downto 0);
c <= signed('0' & a) - b ;
C needs to be one bit bigger. The following should work.
signal a : unsigned(7 downto 0);
signal b : signed(8 downto 0);
signal c : signed(9 downto 0);
c <= signed("00" & a) - b ;
You could also extend b, however, only one of the operands
needs to match the size of the result:
c <= signed("00" & a) - (b(8) & b) ;
On the otherhand, if a is signed (as indicated by your
concern about it being negative), then you need either of
the following two assignments:
signal a : signed(7 downto 0);
signal b : signed(8 downto 0);
signal c1, c2 : signed(9 downto 0);
c1 <= a - (b(8) & b) ;
c2 <= (a(7) & a(7) & a) - (b(8) & b) ;
Cheers,
Jim
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jim Lewis
Director of Training mailto:
[email protected]
SynthWorks Design Inc.
http://www.SynthWorks.com
1-503-590-4787
Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~