THEORY:
Counting 0s and 1s involves iterating through binary data (like a number's binary form, a string, or an array) and tallying each digit, a fundamental task in computer science for understanding binary representations, solving problems like finding the largest subset of binary strings, or implementing bit manipulation, often done by checking each bit or using bitwise operations for efficiency.
module count_ones_zeros_seq (
input clk,
input rst,
input start,
input [7:0] data,
output reg [3:0] ones,
output reg [3:0] zeros,
output reg done
);
integer i;
always @(posedge clk or posedge rst) begin
if (rst) begin
ones <= 0;
zeros <= 0;
i <= 0;
done <= 0;
end
else if (start) begin
if (i < 8) begin
if (data[i])
ones <= ones + 1;
else
zeros <= zeros + 1;
i <= i + 1;
end
else
done <= 1;
end
end
endmodule
POWER:
TIMING:
RTL SCHEMATIC: