|
楼主 |
发表于 2008-5-19 11:11:06
|
显示全部楼层
module multiply(
input[3:0] a,
input[3:0] b,
input clk,
output[7:0] product);
reg[3:0] ma;
reg[7:0] mb;
reg done;
reg[7:0] sum;
reg[3:0] i;
always @(posedge clk)
begin
if(done==1'b0)
begin
if(ma[0]==1'b1) begin sum<=sum+mb; end
i<=i+1;
mb<=mb<<1;
ma<=ma>>1;
end
end
always @(posedge clk)begin
if(i>=4)begin done<=1'b1;end
end
always @(ma or mb or sum)begin
$display("ma=%b,mb=%b,sum=%b",ma,mb,sum);
end
always @(a or b)begin
done=1'b0;
sum=8'b0;
i=4'b0;
ma=a;
mb={4'b0,b};
end
assign product=done?sum:8'b0;
endmodule |
|