Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)

SUm of table

Altera_Forum
Honored Contributor II
1,347 Views

Hi, 

 

Please can you help me to write a Verilog code to calculate sum of table, I have a code that’s calculate with this manner. 

generate 

if(z == 1) 

assign x = y[0]; 

else if (z == 2) 

assign x = y[0] + y[1]; 

else if (z == 3) 

assign x = y[0] +y[1] + y[2] ; 

endgenerate 

I need to let’s this code a generic using a boucle for to calculate sum of table using always block. 

 

Thank you for your helps.
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
663 Views

You don't say how wide your different signals are... 

Assuming z is 2-bits wide, y 3-bits and x 1-bit: 

reg x; always @ (*) case (z): 1 : x = y; 2 : x = y + y; 3 : x = y + y + y; endcase 

 

This would also work if x & y are wider - but the same width as each other - and y an array. 

 

You'll need to specify what happens to x in the case of z == 0. 

 

Regards, 

Alex
0 Kudos
Altera_Forum
Honored Contributor II
663 Views

Thank you very much. problem resolved with this solution.

0 Kudos
Reply