|
发表于 2010-1-29 14:16:31
|
显示全部楼层
用for循环改写的8x8乘法器:
module mux(clk,reset,result,opa,opb);
parameter size = 8;
parameter longsize = 16;
input clk,reset;
input [size-1:0] opa;
input [size-1:0] opb;
output [longsize-1:0] result;
reg [size-1:0] result_m [size-1:0];
reg [longsize-1:0] result;
integer bindex,i;
always @ (negedge clk) begin
if (~reset) begin
for(i=0;i<size;i=i+1) begin
result_m[i] <= 8'h0;
end
end
else begin
for( bindex=0; bindex<size; bindex=bindex+1 ) begin
if(opb[bindex]) begin
result_m[bindex] <=opa;
end
else begin
result_m[bindex] <=8'h0;
end
end
end
end
always @ (negedge clk) begin
if (~reset) result<=8'h0;
else result<=result_m[0]+{result_m[1],1'b0}+{result_m[2],2'b00}+{result_m[3],3'b000}+{result_m[4],4'b0000}+{result_m[5],5'b0_0000}+{result_m[6],6'b00_0000}+{result_m[7],7'b000_0000};
end
endmodule
================
可以用同一个测试程序验证 |
|