for 循环工作正常,但一切都在一个时钟周期内发生。我如何让它每个周期运行一次迭代?
`timescale 1ns/10ps
module multiplier (clock,multiplier,multiplicand,start,done,product);
input [7:0] multiplier ,multiplicand;
input start;
input clock;
output [15:0] product;
output done;
reg [15:0] multiplierF ,multiplicandF;
reg [15:0] productF;
reg doneF;
integer i;
assign product = productF;
assign done = doneF;
task rpa_16;
input [15:0] multiplierF;
inout [15:0] productF;
assign productF = multiplierF + productF;
endtask
always @ (posedge clock or posedge start)
begin
if(start)
begin
multiplierF = 0 ;
multiplicandF = 0 ;
productF = 0 ;
doneF = 0 ;
end
else
begin
multiplierF = {8'b0,multiplier};
multiplicandF = {8'b0,multiplicand};
end
end
always @(posedge clk)
begin
if(!doneF)
begin
for (i=0;i<7;i=i+1)
begin
if(multiplicand[i])
begin
rpa_16(multiplierF,productF);
multiplierF = multiplierF << 1;
productF = productF;
end
else
begin
multiplierF = multiplierF << 1;
end
end
doneF = 1;
end
end