- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much. problem resolved with this solution.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page