![]() |
|
|
|
#1 |
|
Hi:
I have a 8x8 matrix and I want to add all the 64 elements.I tried doing this using two FOR loops,one for row and one for column.It didn't work. Can anyone suggest a method to do this? Thanks, Modukuri Modukuri |
|
|
|
|
#2 |
|
Posts: n/a
|
Create a two dimensional array of type unsigned or
signed as is appropriate for your problem. Include the package: use ieee.numeric_std.all ; If you still have problems, provide your code and so people can point you in the right direction. Cheers, Jim > Hi: > > I have a 8x8 matrix and I want to add all the 64 elements.I tried > doing this using two FOR loops,one for row and one for column.It > didn't work. > Can anyone suggest a method to do this? > > Thanks, > Modukuri -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ Jim Lewis Director of Training private.php?do=newpm&u= SynthWorks Design Inc. http://www.SynthWorks.com 1-503-590-4787 Expert VHDL Training for Hardware Design and Verification ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ Jim Lewis |
|
|
|
#3 |
|
Posts: n/a
|
Modukuri wrote:
> I have a 8x8 matrix and I want to add all the 64 elements. => 63 additions (quite a lot...) > I tried > doing this using two FOR loops,one for row and one for column.It > didn't work. > Can anyone suggest a method to do this? First decide, if it is really nessecary to add them in parallel. (-> Serialized addition; Pipelining?) Next, you should think about a tree-based or an array-based adder. The simplest form can be described this way: sum1<=((a+b) + (c+d)) + ((e+f) + (g+h)); -- tree sum2<=(((((((a+b)+c)+d)+e)+f)+g)+h); -- array (I did not care for the carry-out (-> overflow).) Ralf Ralf Hildebrandt |
|
|
|
#4 |
|
Posts: n/a
|
Hi:
This is the code,I'm using to sum all the elements of an array.But,at the end of simulation,signal "sum" has only the last element of the matrix,not the sum of all the 64 elements.I would really appreciate any corrections/suggesstions to the code. type diff_matrix is array (0 to 7,0 to 7) of integer; signal diff : diff_matrix; signal sum : integer; process(clk,reset) begin if reset = '1 then sum <= 0; elsif (clk'event and clk = '1') then for i in 0 to 7 loop for j in 0 to 7 loop sum <= sum_ini + diff(i,j); end loop; end loop; end process; Thanks, Modukuri Jim Lewis <> wrote in message news:<>... > Create a two dimensional array of type unsigned or > signed as is appropriate for your problem. Include the > package: > use ieee.numeric_std.all ; > > If you still have problems, provide your code and > so people can point you in the right direction. > > Cheers, > Jim > > > Hi: > > > > I have a 8x8 matrix and I want to add all the 64 elements.I tried > > doing this using two FOR loops,one for row and one for column.It > > didn't work. > > Can anyone suggest a method to do this? > > > > Thanks, > > Modukuri > > > -- > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ > Jim Lewis > Director of Training private.php?do=newpm&u= > SynthWorks Design Inc. http://www.SynthWorks.com > 1-503-590-4787 > > Expert VHDL Training for Hardware Design and Verification > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ Modukuri |
|
|
|
#5 |
|
Posts: n/a
|
The problem is, that the two loops are actually run through in the same simulation cycle, you could think of them being concurrent. So every time you assign something to sum, the driver of sum is updated, not the signal itself tho. Naturally the last assignment is that of the last element of the matrix, which then stays in the driver and is assigned to the signal in the next simulation cycle. However, the code would work if you used variables instead of signals. Something like this maybe: type diff_matrix is array (0 to 7,0 to 7) of integer; signal diff : diff_matrix; signal sum : integer; variable temp : integer; process(clk,reset) begin if reset = '1 then sum <= 0; elsif (clk'event and clk = '1') then for i in 0 to 7 loop for j in 0 to 7 loop temp := temp + diff(i,j); end loop; end loop; sum <= temp end if; end process; On 30 May 2004 14:17:11 -0700, (Modukuri) wrote: >Hi: > >This is the code,I'm using to sum all the elements of an array.But,at >the end of simulation,signal "sum" has only the last element of the >matrix,not the sum of all the 64 elements.I would really appreciate >any corrections/suggesstions to the code. > >type diff_matrix is array (0 to 7,0 to 7) of integer; >signal diff : diff_matrix; >signal sum : integer; > >process(clk,reset) >begin > if reset = '1 then > sum <= 0; > elsif (clk'event and clk = '1') then > for i in 0 to 7 loop > for j in 0 to 7 loop > sum <= sum_ini + diff(i,j); > end loop; > end loop; >end process; > > >Thanks, >Modukuri > > > >Jim Lewis <> wrote in message news:<>... >> Create a two dimensional array of type unsigned or >> signed as is appropriate for your problem. Include the >> package: >> use ieee.numeric_std.all ; >> >> If you still have problems, provide your code and >> so people can point you in the right direction. >> >> Cheers, >> Jim >> >> > Hi: >> > >> > I have a 8x8 matrix and I want to add all the 64 elements.I tried >> > doing this using two FOR loops,one for row and one for column.It >> > didn't work. >> > Can anyone suggest a method to do this? >> > >> > Thanks, >> > Modukuri >> >> >> -- >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ >> Jim Lewis >> Director of Training private.php?do=newpm&u= >> SynthWorks Design Inc. http://www.SynthWorks.com >> 1-503-590-4787 >> >> Expert VHDL Training for Hardware Design and Verification >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ Christoph M. Wintersteiger |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| constants as of array of integers, for loops | octavsly | Hardware | 0 | 04-25-2009 11:53 AM |
| How to retrieve array parameter ( JAVA ) | naruponk | Software | 1 | 04-16-2009 10:20 AM |
| Array Programme | rits | Software | 2 | 03-04-2009 05:18 PM |
| How To Access HTML elements in code behind??? | nedums_b | Software | 1 | 02-07-2008 07:15 PM |
| Paramount postpones Tuesday release of Star Trek DVD, elements missing. | Allan | DVD Video | 2 | 09-09-2004 03:50 PM |