You are on page 1of 3

Vlsi architectures for signal processing

1. ACCUMULATOR
Verilog code:
module accumulator (
input [7:0] A, // Input data
input clk, // Clock signal
input clr, // Asynchronous clear
output reg [7:0] accum, // Accumulator output
output reg overflow // Overflow flag
);

always @(posedge clk) begin


if (~clr) begin
accum <= 8'b00000000; // Clear accumulator
overflow <= 1'b0; // Clear overflow flag
end else begin
{overflow, accum} <= accum + A; // Add input to accumulator
end
end

endmodule

Testbench:
module tb_accumulator;

// Parameters
reg [7:0] A; // Input data
reg clk; // Clock signal
reg clr; // Asynchronous clear
wire [7:0] accum; // Accumulator output
wire overflow; // Overflow flag
// Instantiate the accumulator module
accumulator dut (
.A(A),
.clk(clk),
.clr(clr),
.accum(accum),
.overflow(overflow)
);

// Clock generation
always begin
#5 clk = ~clk;
end

// Testbench stimulus
initial begin
$dumpfile("accumulator.vcd");
$dumpvars(0, tb_accumulator);

// Initialize signals
A = 8'b01010101; // Example input value
clr = 1'b0; // Not clearing

// Apply input and observe output


#10;
A = 8'b11001100; // New input value
clr = 1'b1; // Clearing
#20;

// Add more test cases as needed

$finish;
end

endmodule

You might also like