乘法器的学习
今天开始写技术博客,每天都写一部分看看自己可以坚持多久。
今天学习了一下黑金上的资料的,今天先讲一下乘法器的心得体会
在进行设计时,首先将乘数和被乘数的首位进行异或运算,对数据的正负进行判断。然后不断地将被乘数加到开辟的乘积空间中。每加一次就对乘数进行减一操作,直到乘数变为零。一下贴出一些核心代码
always @(posedge clk or negedge rst_n)
if(!rst_n)
begin
rMultiplicand<=8'd0;
rMultiplier<=8'd0;
i<=2'd0;
temp<=16'd0;
end
else if(Start_Sig)
case(i)
0: begin
isNeg<=Multiplier[7]^Multiplicand[7];//异或运算,判断是否有负数
rMultiplicand<=Multiplicand[7]?(~Multiplicand+1'b1):Multiplicand;
rMultiplier<=Multiplier[7]?(~Multiplier+1'b1):Multiplier;
i<=i+1'b1;
temp<=16'd0;//一定要注意这里要清零,我就是在编程时没有注意,导致后面进行仿真时,结果出错
end
1:
if(rMultiplier==0) i<=i+1'b1;
else
begin
temp<=temp+rMultiplicand;
rMultiplier<=rMultiplier-1'b1;
end
2: begin
i<=i+1'b1;
isDone<=1'b1;
end
3: begin
isDone<=1'b0;
i<=2'b0;
end
endcase
我就进行了仿真文件的设计,
always@(posedge clk or negedge rst_n )
if(!rst_n )
begin
i<=4'b0;
Start_Sig<=1'b0;
Multiplicand<=8'd0;
Multiplier<=8'd0;
end
else
case(i)
0:
if(Done_Sig)
begin
i<=i+1'b1;
Start_Sig<=1'b0;
end
else
begin
Multiplier<=8'd27;
Multiplicand<=8'd25;
Start_Sig=1'b1;
end
1:
if(Done_Sig)
begin
i<=i+1'b1;
Start_Sig<=1'b0;
end
else
begin
Multiplier<=8'd29;
Multiplicand<=8'b11011101;
Start_Sig=1'b1;
end
2:
if(Done_Sig)
begin
i<=i+1'b1;
Start_Sig<=1'b0;
end
else
begin
Multiplier<=8'd2;
Multiplicand<=8'd5;
Start_Sig=1'b1;
end