0% found this document useful (0 votes)
8 views6 pages

Full Adder and 4-Bit Adder Module

The document describes the implementation of a Full Adder and a 4-bit Parallel Adder in Verilog, detailing the input and output specifications, as well as the internal logic used for summation and carry operations. Additionally, it includes a testbench for the 4-bit Parallel Adder to validate its functionality through various test cases. Furthermore, it outlines the Booth's Multiplication algorithm in a module, which includes state management and arithmetic operations for signed multiplication.

Uploaded by

prafullaenc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Full Adder and 4-Bit Adder Module

The document describes the implementation of a Full Adder and a 4-bit Parallel Adder in Verilog, detailing the input and output specifications, as well as the internal logic used for summation and carry operations. Additionally, it includes a testbench for the 4-bit Parallel Adder to validate its functionality through various test cases. Furthermore, it outlines the Booth's Multiplication algorithm in a module, which includes state management and arithmetic operations for signed multiplication.

Uploaded by

prafullaenc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

// Full Adder Module: Computes sum and carry for single-bit addition

module fulladder (a, b, cin, sum, carry);

input a, b, cin; // Inputs: Two bits (a, b) and carry-in (cin)

output sum, carry; // Outputs: Sum and carry-out

assign sum = a ^ b ^ cin; // XOR operation for sum calculation

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

module parellel (a, b, cin, sum, carry);

input [3:0] a, b; // 4-bit input operands

input cin; // Carry-in

output [3:0] sum; // 4-bit sum output

output carry; // Carry-out

wire [3:1] w; // Internal wires to carry intermediate carries

fulladder fa0(a[0], b[0], cin, sum[0], w[1]); // LSB addition

fulladder fa1(a[1], b[1], w[1], sum[1], w[2]); // Next bit addition

fulladder fa2(a[2], b[2], w[2], sum[2], w[3]); // Next bit addition

fulladder fa3(a[3], .b[3], w[3], sum[3], carry); // MSB addition, final carry-out

endmodule

// Testbench for 4-bit Parallel Adder

module parallel_tb;

reg [3:0] a, b; // 4-bit registers for inputs


reg cin; // Single-bit register for carry-in

wire [3:0] sum; // 4-bit wire for sum output

wire carry; // Wire for carry-out

// Instantiate the parallel adder module

parallel uut (a, b, cin, sum, carry);

initial begin

// First test case

a = 4'b0111; b = 4'b0100; cin = 1'b0;

#10; // Wait 10 time units

// Second test case

a = 4'b1011; b = 4'b0110; cin = 1'b1;

#10; // Wait 10 time units

// End simulation after some time

$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

// Module definition for Booth's Multiplier

module BoothMul(clk, rst, start, X, Y, valid, Z);

// Input declarations

input clk; // Clock signal

input rst; // Reset signal (active low)

input start; // Start signal to initiate multiplication

input signed [3:0] X, Y; // 4-bit signed inputs (multiplicand and multiplier)

// Output declarations

output signed [7:0] Z; // 8-bit signed output (product)

output valid; // Output signal indicating valid result

// Internal register 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] temp, next_temp; // Registers to hold the concatenated bits of X

reg [1:0] count, next_count; // Counter registers to track the number of iterations

reg valid, next_valid; // Registers for valid signal

// State encoding

parameter IDLE = 1'b0; // IDLE state

parameter START = 1'b1; // START state


// Sequential logic: State and register update on clock edge or reset

always @ (posedge clk or negedge rst) begin

if (!rst) begin

// Asynchronous reset: Initialize all registers to default values

Z <= 8'd0;

valid <= 1'b0;

pres_state <= IDLE;

temp <= 2'd0;

count <= 2'd0;

end else begin

// Update registers with next state values

Z <= next_Z;

valid <= next_valid;

pres_state <= next_state;

temp <= next_temp;

count <= next_count;

end

end

// Combinational logic: Next state and output logic

always @ (*) begin

case (pres_state)

IDLE: begin

// Default assignments for IDLE state

next_count = 2'b0;
next_valid = 1'b0;

if (start) begin

// On start signal, initialize for multiplication

next_state = START;

next_temp = {X[0], 1'b0}; // Concatenate LSB of X with 0

next_Z = {4'd0, X}; // Initialize Z with X in lower 4 bits

} else begin

// Remain in IDLE state

next_state = IDLE;

next_temp = 2'd0;

next_Z = 8'd0;

end

end

START: begin

// Booth's algorithm operation based on temp value

case (temp)

2'b10: Z_temp = {Z[7:4] - Y, Z[3:0]}; // Subtract Y from upper 4 bits of Z

2'b01: Z_temp = {Z[7:4] + Y, Z[3:0]}; // Add Y to upper 4 bits of Z

default: Z_temp = Z; // No operation

endcase

// Prepare for next iteration

next_temp = {X[count + 1], X[count]}; // Update temp with next bits of X

next_count = count + 1'b1; // Increment count

next_Z = Z_temp >>> 1; // Arithmetic right shift of Z_temp


// Check if all bits have been processed

next_valid = (&count) ? 1'b1 : 1'b0; // Set valid signal if count is all ones

next_state = (&count) ? IDLE : START; // Return to IDLE if done, else continue

end

endcase

end

endmodule

Common questions

Powered by AI

Booth's Multiplier utilizes state transitions and arithmetic operations embedded within a Finite State Machine (FSM) to perform multiplication. Starting from the IDLE state upon receiving the `start` signal, it initializes the multiplicand (`X`) and sets up initial conditions. The module processes the multiplication by entering the START state, where the core operations depend on a `temp` variable representing bits of the multiplicand and multiplier. Based on the value of `temp`, arithmetic operations such as addition or subtraction of the multiplier (`Y`) onto the upper bits of the working product register (`Z`) are executed. The `Z` register undergoes arithmetic right shifts in every iteration. The FSM transitions back to IDLE when all bits are processed, ensuring `Z` contains the final product while maintaining flow control using the `valid` signal to indicate completion of multiplication .

The `temp` variable in Booth's Multiplier is pivotal in guiding the iterative steps of multiplication, serving as a decision-maker for arithmetic operations within each cycle. It is derived by concatenating bits from the multiplicand (`X`) and controls whether to perform addition, subtraction, or no operation on the multiplied value residing in the upper bits of `Z`. Specific patterns in `temp` determine whether `Y` (multiplier) should be added to or subtracted from `Z` to accommodate the two's complement representation shifts. It enables efficient processing by dynamically adjusting operations per bit conditions, thus optimizing multiplication steps based on Booth's algorithm .

The asynchronous reset in digital designs like Booth's Multiplier is critically important as it ensures that all internal registers and states are initialized to known default values regardless of the clock state. This feature is vital for system reliability and predictable behavior upon power-up or when returning to a default state after a fault. It effectively sets the product register (`Z`) to zero, resets the `valid` signal, state registers, and counters, making the design robust against unwanted initialization states and ensuring a clean start from a specific, controlled condition .

The 4-bit Parallel Adder uses a sequence of Full Adders to handle each bit of the 4-bit inputs `a` and `b`, including the carry-in `cin`. Internal wires carry intermediate carry-out values between Full Adders to ensure cumulative addition. The first Full Adder computes the least significant bit (`fa0`) and its carry-out is passed as the carry-in for the next bit, and this process continues for the entire bit-width. The structure ensures each bit addition considers the carry from the previous bit, and these Full Adders are connected in a cascading configuration, leading to accurate result in terms of both sum and carry-out .

The combinational logic block in Booth's Multiplier defines the next state and output values by evaluating the current state (`pres_state`) and the `temp` variable, representing multiplicand's bit-pairs. During the `START` state, depending on `temp` values, it decides whether to add, subtract, or maintain `Y` in the computation based on Booth's criteria. This logic then updates the working product (`next_Z`) and shifts it right for the next stage. It concurrently checks completion of the operations through `count` and routes to either continue in `START` or return to `IDLE`. It ensures computation progresses correctly step-by-step, enabling correct state transitions and output validity without clock dependence, using logical conditions derived from state-machine operational rules .

The testbench plays a crucial role in verifying the functionality of the 4-bit Parallel Adder by simulating different scenarios and observing the adder's behavior. It defines inputs for two test cases, simulating different values of 4-bit numbers `a` and `b`, with different `cin` values. The first test case uses `a=4'b0111`, `b=4'b0100`, and `cin=1'b0`, observing outputs after a delay. The second test case uses `a=4'b1011`, `b=4'b0110`, and `cin=1'b1`. The `$monitor` command logs the input-output relationship in real-time during simulation, providing insights into adder's operations, ensuring the design is functionally correct under varied input conditions .

In the Parallel Adder Module, input registers (`a` and `b`) define storage locations for the 4-bit binary numbers being added and serve as static inputs for the operation. These registers store values that do not change during the adder operation and are crucial in providing initial data. Conversely, internal wires serve as temporary conduits for carrying intermediate results, specifically the carry bits between successive Full Adders. They dynamically transfer information, enabling continuous bitwise operations. While input registers capture and hold input signals, internal wires ensure sequential logic handling, reflecting their contrasting functions: storage vs. real-time communication .

The arithmetic right shift mechanism is crucial in Booth's Algorithm, especially after every arithmetic operation like addition or subtraction. It ensures correct sign extension for the intermediate product in `Z`, essential when working with signed numbers. This operation maintains the most significant bit's value across shifts, preserving the numerical sign integrity essential for signed representations. Such right shifts, applied consistently, effectively divide the intermediate result by two while preserving its sign indication, facilitating correct future additions or subtractions during next state operations, ultimately ensuring that the final result is correctly scaled according to Booth’s method .

The testbench manages timing between operations in verifying digital module designs by using time delays after each operation to simulate the passage of time within a digital clock cycle. In the case of a parallel adder testbench, after setting inputs, it waits a specified duration (`#10`) allowing the circuit's propagation delays to stabilize before checking the outputs. This delay ensures that the changes in inputs have enough time to propagate through the combinational logic of the adder and that the output responses accurately represent the circuit's functionality under the specified timing constraints .

The Full Adder Module computes the sum and carry for single-bit addition using XOR operations for the sum and a combination of AND and OR operations for the carry. The sum is calculated as the XOR of inputs `a`, `b`, and `cin` (carry-in), expressed as `sum = a ^ b ^ cin`. The carry-out is derived from the logical expression `carry = (a & b) | (b & cin) | (cin & a)` which ensures that a carry-out only occurs if at least two of the three inputs are true .

You might also like