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.

how to add multiple unsigned values?

Status
Not open for further replies.

milan.km

Member level 3
Joined
Sep 14, 2015
Messages
55
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
435
hi...
I want to add nine usigned,8 bit values,but I have the warning that the length dont match?
how can I fix it?
thanks
a : unsigned(11 downto 0);
a1,a2,a3,a4,a5,a6,a7,a8,a9 : unsigned(7 downto 0)
a=a1+a2+a3+a4+a5+a6+a7+a8+a9 ;
warning :Length of expected is 12; length of actual is 8.
 

hi...
I want to add nine usigned,8 bit values,but I have the warning that the length dont match?
how can I fix it?
thanks
a : unsigned(11 downto 0);
a1,a2,a3,a4,a5,a6,a7,a8,a9 : unsigned(7 downto 0)
a=a1+a2+a3+a4+a5+a6+a7+a8+a9 ;
warning :Length of expected is 12; length of actual is 8.

Adding numbers potentially add bits of precision to the computation, but the numeric_std library doesn't resize the result of an addition for you. One way to solve is to resize one of the signals that are being added and then do the summation (or could you resize all 9 of the signals and sum the resized signals).

a=resize(a1, a'length)+a2+a3+a4+a5+a6+a7+a8+a9;

Another way involves using the fixed point type ufixed rather than unsigned. ufixed does resize the output of the '+' operation to add a bit. But since you're performing eight adds, I believe it will create a 16 bit result so you'll still have to resize the end result like this:

a=resize(a1+a2+a3+a4+a5+a6+a7+a8+a9, a'length);
Kevin
 

For n values of length 8 bits, the result will be a maximum of 8 plus the number of bits of n
for n=9 decimal= 0000 1001 this can be reduced to 4 bits so the expected result requires 4+8 bits meaning double precision or extended length to 12 at a minimum.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top