Full Adder Module
Full Adder Module
assign carry = (a & b) | (b & cin) | (cin & a); // Carry logic using AND and OR
endmodule
// 4-bit Parallel Adder Module: Adds two 4-bit numbers with carry-in
fulladder fa3(a[3], .b[3], w[3], sum[3], carry); // MSB addition, final carry-out
endmodule
module parallel_tb;
initial begin
$finish;
End
initial begin
$monitor($time, " a=%b b=%b cin=%b => sum=%b carry=%b", a, b, cin, sum, carry);
end
endmodule
BOOTH ALGORITHM
// Input declarations
// Output declarations
reg signed [7:0] Z, next_Z, Z_temp; // Registers to hold the product and intermediate values
reg next_state, pres_state; // Registers for current and next state in FSM
reg [1:0] count, next_count; // Counter registers to track the number of iterations
// State encoding
if (!rst) begin
Z <= 8'd0;
Z <= next_Z;
end
end
case (pres_state)
IDLE: begin
next_count = 2'b0;
next_valid = 1'b0;
if (start) begin
next_state = START;
} else begin
next_state = IDLE;
next_temp = 2'd0;
next_Z = 8'd0;
end
end
START: begin
case (temp)
endcase
next_valid = (&count) ? 1'b1 : 1'b0; // Set valid signal if count is all ones
end
endcase
end
endmodule