// 8-bit accumulator with clear, enable and carry-out. // On each rising edge: // rst or clr : acc <= 0, carry <= 0 (clr has priority over en) // en : {carry, acc} <= acc + din // otherwise : hold `timescale 1ns / 1ps module accum8 ( input logic clk, input logic rst, // synchronous, active high input logic clr, // synchronous clear input logic en, // add din this cycle input logic [7:0] din, output logic [7:0] acc, output logic carry // carry-out of the most recent addition ); always_ff @(posedge clk) begin if (rst || clr) begin acc <= 8'd0; carry <= 1'b0; end else if (en) begin {carry, acc} <= {1'b0, acc} + {1'b0, din}; end end endmodule