|
本帖最后由 fpgaw 于 2010-11-19 18:45 编辑
这是一个二进制的8X8的乘法器,请哪位帮忙看看!
module mul_ser (clk, x, a, y);
input clk;
input[7:0]x, a;
output [15:0] y;
reg [15:0] y;
always @(posedge clk)
begin : States
parameter s0=0, s1=1, s2=2;
reg [2:0] count;
reg [1:0] state;
reg[15:0] p, t;
reg[7:0] a_reg;
case (state)
s0 : begin
a_reg <= a;
state <= s1;
count = 0;
p <= 0;
t <= {{8{x[7]}},x};
end
s1 : begin
if (count == 7)
state <= s2;
else
begin
if (a_reg[0] == 1)
p <= p + t;
a_reg <= a_reg >> 1;
t <= t << 1;
count = count + 1;
state <= s1;
end
end
s2 : begin
y <= p;
state <= s0;
end
endcase
end
endmodule |
|