title: Modified booth multiplication algorithm
body: <p>I use ModelSim to simulate booth multiplication. I have this code but it's true when <code>b = 5</code>, and when I give other numbers for <code>b</code> the result is like this=65563.<br>
  I try both signed and unsigned but the result is false.
  I just confused where is problem.</p>
  
  <pre><code>module multiply(p,a,b,clock);
  output [15:0] p;
  input [7:0]  a,b;
  input clock;
  reg [15:0] p,ans;
  integer i;
  integer operate;
  initial
  begin
    p=16'b0;
    ans=16'b0;
  end
  always @(negedge clock)
  begin
    p=16'b0;
    for(i=1;i&lt;=7;i=i+2)
    begin
      if(i==1)
        operate=b[0]-b[1]-b[1];
      else
        operate=b[i-1]-b[i-2]-b[i]-b[i];
        case(operate)
          1:
          begin
            ans=a;
            ans=ans&lt;&lt;(i-1);
            p=p+ans;
          end
          2:
          begin
            ans=a&lt;&lt;1;
            ans=ans&lt;&lt;(i-1);
            p=p+ans;
          end
          -1:
          begin
            ans=~a+1;
            ans=ans&lt;&lt;(i-1);
            p=p+ans;
          end
          -2:
          begin
            ans=a&lt;&lt;1;
            ans=~ans+1;
            ans=ans&lt;&lt;(i-1);
            p=p+ans;
          end
        endcase
      end
    end
  endmodule
  </code></pre>