I did a 8 bit by 8 bit before,but it was not generic. i cant figure out how to adjust the code to make it NxM bit . can anyone help me?
Asked
Active
Viewed 1,385 times
-1
-
3You'll increase your chances of getting an answer if you add some code and show what you tried to make it generic. – ByteWelder Apr 01 '16 at 15:25
-
Parameterize your code? – wilcroft Apr 01 '16 at 15:42
1 Answers
2
You need to use parameters. Parameters are basically input constants and are a good way of writing generic code. They sit between the name of the module and the ports in a list that looks like the port list, but is preceded by a hash:
module <MODULE NAME> #(<SOME TYPE> <PARAMETER NAME>=<DEFAULT_VALUE>, ...) (<THE PORTS>);
The ports themselves can be declared using the parameters. It is common to use a parameter to, for example, define the widths of inputs and outputs.
Here is an example (using an MxN multiplier):
module MULT #(integer M=8, integer N=8) (input [M-1:0] A, [N-1:0] B, [(M+N)-1:0] F);
assign F = A * B;
endmodule
http://www.edaplayground.com/x/2Bvx
So, it's very easy if you're happy to just synthesize your multiplier. If your multiplier design is more structural, then you're going to have to learn about generate
loops.

Victor Lyuboslavsky
- 9,882
- 25
- 87
- 134

Matthew Taylor
- 13,365
- 3
- 17
- 44