tabascorez
Junior Member level 2
- Joined
- Nov 11, 2013
- Messages
- 22
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 163
Hello
May somebody please help me with this. I have the following code, and now I want to use it to implement a variable length multiplier. How can I expand this code in order to achieve this?
May somebody please help me with this. I have the following code, and now I want to use it to implement a variable length multiplier. How can I expand this code in order to achieve this?
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 module booth_mul #(parameter WIDTH=4) (input clk, input enable, input [WIDTH-1:0]multiplier, input [WIDTH-1:0]multiplicand, output reg [2*WIDTH-1:0]product); parameter IDLE = 2'b00, ADD = 2'b01, SHIFT = 2'b10, OUTPUT = 2'b11; reg [1:0] current_state, next_state; reg [2*WIDTH+1:0] a_reg,s_reg,p_reg,sum_reg; reg [WIDTH-1:0] iter_cnt; wire [WIDTH:0] multiplier_neg; 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 assign multiplier_neg = -{multiplier[WIDTH-1],multiplier}; 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; 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: product = p_reg>>1; endcase end endmodule