Verilog Booth Multiplier
Submitted by abettino on Sat, 03/13/2010 - 17:24
This snippet demonstrates a booth encoder implementation in Verilog. There is a state machine that controls the adding and shifting operations. The enable and done are the top level control and status signals. Included in the attached file is a test bench to exercise the module.
module booth #(parameter WIDTH=4) ( input clk, input enable, input [WIDTH-1:0] multiplier, input [WIDTH-1:0] multiplicand, output reg done, output reg [2*WIDTH-1:0] product ); // state encodings. parameter IDLE = 2'b00, ADD = 2'b01, SHIFT = 2'b10, OUTPUT = 2'b11; reg [1:0] current_state, next_state; // state registers. reg [2*WIDTH+1:0] a_reg,s_reg,p_reg,sum_reg; // computational values. reg [WIDTH-1:0] iter_cnt; // iteration count for determining when done. wire [WIDTH:0] multiplier_neg; // negative value of multiplier // state machine. always @(posedge clk) if (!enable) current_state = IDLE; else current_state <= next_state; always @* begin next_state = 2'bx; case (current_state) IDLE : if (enable) next_state = ADD; else next_state = IDLE; ADD : next_state = SHIFT; SHIFT : if (iter_cnt==WIDTH) next_state = OUTPUT; else next_state = ADD; OUTPUT : next_state = IDLE; endcase end // negative value of multiplier. assign multiplier_neg = -{multiplier[WIDTH-1],multiplier}; // algorithm implemenation details. always @(posedge clk) begin case (current_state) IDLE : begin a_reg <= {multiplier[WIDTH-1],multiplier,{(WIDTH+1){1'b0}}}; s_reg <= {multiplier_neg,{(WIDTH+1){1'b0}}}; p_reg <= {{(WIDTH+1){1'b0}},multiplicand,1'b0}; iter_cnt <= 0; done <= 1'b0; end ADD : begin case (p_reg[1:0]) 2'b01 : sum_reg <= p_reg+a_reg; 2'b10 : sum_reg <= p_reg+s_reg; 2'b00,2'b11 : sum_reg <= p_reg; endcase iter_cnt <= iter_cnt + 1; end SHIFT : begin p_reg <= {sum_reg[2*WIDTH+1],sum_reg[2*WIDTH+1:1]}; end OUTPUT : begin product <= p_reg[2*WIDTH:1]; done <= 1'b1; end endcase end endmodule
| Attachment | Size |
|---|---|
| booth.v | 3.38 KB |

test bench
Thanku sir it is very useful. can u please provide me the test bench for this code
Verilog Booth Multiplier
Can u tell me how to convert this code into 8 by 8 multiplier please
it is very urgent thank you
I have the code for 8*8 bit
I have the code for 8*8 bit multiplier. It was a question my exams my professor did not approve of the code so I demonstrated the whole code perfectly in front of re-check panel and it worked.
Give me your mail address ill send it to you
8 bit
Read through basics on "parameter" for Verilog. It is quite easier. You have to insert 8 in (), i.e (8) when instantiating the module booth and the resulting module is 8 bit multiplier.
This is very inefficient
The add and shift can be merged into a single cycle operation. Amount of logic still rmains the same, rather it will decrease a little as one state is being removed.
About merge the state
why is it inefficient after merging the add and shift ? is it straight merging?