3位二进制乘3位二进制思路:3位乘3位得6位;
例如 110 * 011 = 010010
000_110
+ 001_100
-----------------------
010_010
读入数据 3次移位判断 输出 用了5个时钟周期得到一个结果 100M/5=20M
module mul_ser (clk, x, a, y,rst);
input clk;
input rst;
input [2:0] x, a;
output [5:0] y;
reg [5:0] y;
reg [1:0] state;
reg [2:0] count;
reg [5:0] p, t; // Double bit width
reg [2:0] a_reg;
parameter s0=0, s1=1, s2=2;
always @(posedge clk or posedge rst) //-> Multiplier in behavioral style
if(rst) state <= 3'b0;
else begin : States
case (state)
s0 : begin // Initialization step
a_reg <= a;
state <= s1;
count = 0;
p <= 0; // Product register reset
t <= {{3{1'b0}},x}; // Set temporary shift register
end // to x
s1 : begin // Processing step
if (count == 3'd3) // Multiplication ready
state <= s2;
else // Note that MaxPlusII does not does
begin // not allow variable bit selects,
if (a_reg[0] == 1) // see (LRM Sec. 4.2.1)
begin
p <= p + t; // Add 2^k
end
a_reg <= a_reg >> 1;// Use LSB for the bit select
t <= t << 1;
count = count + 1;
state <= s1;
end
end
s2 : begin // Output of result to y and
y <= p; // start next multiplication
state <= s0;
end
endcase
end
endmodule