Professional Documents
Culture Documents
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
);
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
$finish;
end
endmodule