The booth algorithm takes full advantage of the importance of the complement, which allows us to reduce a lot of timing when we use the complement to calculate. The following table is an analysis of what we assume as a multiplier of 2. Next, I'll use the code to explain to you.
1, the beginning of the multiplier 2 of the ' negative one ' plus a default value of 0 |
00100 |
2, first judge [0:-1], the result is 2 ' b00, means ' 0 ' is no operation |
00100 |
3. Judging [1:0] The result is 2 ' b10, which means ' 1 ' i.e. '-by multiplier ' operation |
00100 |
4, Judge "2:1" result is 2 ' b10, means ' 1 ' is ' + by multiplier ' operation |
00100 |
5, Judge "3:2" result is 2 ' b00, means ' 0 ' is no operation |
00100 |
This test carries out two eight-digit multiplication operations.
[Email protected] (Posedge CLK or Negedge rst_n)
if (!rst_n)
Begin
I<=4 ' B0;
A<=8 ' B0;
B<=8 ' B0;
S<=8 ' B0;
P<=17 ' B0;
X<=4 ' B0;
Isdone<=1 ' B0;
End
else if (Start_sig)
Case (i)
0:
Begin
a<=a;
s<= (~a+1 ' B1);
P<={8 ' d0,b,1 ' B0};
I<=i+1 ' B1;
End
1:
if (x==8)
Begin
X<=4 ' D0;
I<=i+4 ' D2;
End
else if (p[1:0]==2 ' B01)
Begin
p<={p[16:9]+a,p[8:0]};
I<=i+1 ' B1;
End
else if (p[1:0]==2 ' B10)
Begin
p<={p[16:9]+s,p[8:0]};
I<=i+1 ' B1;
End
else I<=i+1 ' B1;
2:
Begin
p<={p[16],p[16:1]};
X<=x+1 ' B1;
I<=i+1 ' B1;
End
3:
Begin
Isdone<=1 ' B1;
I<=i+1 ' B1;
End
4:
Begin
I<=3 ' B0;
Isdone<=1 ' B0;
End
Endcase
The above is the core code, here we will be the multiplier A into two registers, a storage source data A, a storage complement s. Put the multiplier B into the P space for the shift operation.
Also set shift counter X to stop execution when 8 bits are reached. Otherwise, we will judge the last two bits of data if p[1:0] is 10, then p[16:9]+s, low eight-bit hold, if p[1:0]=01, then p[16:9]+a, low eight-bit hold. All the rest remained.
In the next step, the shift operation, the first is what to complement what, the data to move to the right. We can see the results by testing the files.
The booth algorithm implements the multiplier