分布式乘法器
module distributed
#(parameter width=3,parameter width2 = 8)/*调试错误一*/
(
input clk,
input [width - 1 : 0] in_data,
output [width2-1 : 0] out_data,
output[3 : 0] rom_data,
output flag
);
//reg flag;/*用上面的方式定义的端口是不能这样来定义的*/
reg [width2-1:0] out_data_r1,out_data_r2;
reg[3:0] rom_out;
reg flag_r;
integer counter ;/*调试错误二,integer 不能改为reg*/
lpm_rom rom1/*ROM块的调用*/
(.address(in_data), .inclock(clk), .outclock(clk), .q(rom_out));
defparam rom1.lpm_width = (width + 1);
defparam rom1.lpm_widthad = width;
defparam rom1.lpm_file = "distributed_rom.mif";
always@(posedge clk)
begin
counter <= counter + 1;
if(counter < 2)
begin
out_data_r1 <= 8'd0;
flag_r <= 0;
end
else if(counter >5)
begin
counter <= 0;
out_data_r1 <= 0;
out_data_r2 <=out_data_r1;
flag_r <= 0;
end
else
begin
out_data_r1 <= out_data_r1 + ( {4'd0,rom_out} <<( counter-2));
flag_r <= 1;
end
end
assign out_data = out_data_r2;
assign rom_data = rom_out;
assign flag = flag_r;
endmodule