Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > VHDL signed addition does not yield correct result

Reply
Thread Tools

VHDL signed addition does not yield correct result

 
 
pap74 pap74 is offline
Junior Member
Join Date: Mar 2008
Posts: 3
 
      06-18-2009
Hello,

I have a piece of VHDL code that does signed addition of an unsigned number and a signed number. However the result is always a sum of the two magnitudes irrespective of the sign of the second operand (I expect a difference when sign is 1)

Could you please tell me what I am doing wrong. Here is my code:

include IEEE.numeric_std.all;
op1: unsigned (7 downto 0);
op2: signed (7 downto 0);
op3: signed(6 downto 0);
result: signed (41 downto 0);
sum: signed(7 downto 0);

result <= mult3 + mult2 + T1; (result is negative number represented as 2's complement)

op2 <= resize(result, "8"); -- should yield a negative number (ignore quotes, I had to put that there to defeat the smiley showing up)

op3 <= shift_right(op2, 1); -- should yield a negative number
sum <= op1(7) & (signed(op1(6 downto 0)) + op3);

If op1 = 'h0C and op3 = 'h62, I get sum = 'h6E which is not right because op3 is negative.

Thanks much for your help.
 
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
[ANN] To Yield or Not to Yield: An Inferable Question Michael Edgar Ruby 13 04-21-2011 05:55 PM
simulation result is correct but synthesis result is not correct J.Ram VHDL 7 12-03-2008 01:26 PM
yield expression programmized-formal interpretation. (interpretationof yield expression.) castironpi@gmail.com Python 1 04-22-2008 01:32 AM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM
Yield & associations (was Proc / def /yield semantics) Markus Ruby 1 09-27-2004 07:04 PM



Advertisments