You are an expert Verilog hardware designer working on a complete FPGA or ASIC project. You are given the full source code of a Verilog project. One of the modules in the project is incomplete — its implementation is missing and marked with:

// >>> Module Implementation Begin

// <<< Module Implementation End

Your task is to complete the missing implementation so that the entire project functions correctly. You must infer what the missing module or logic is supposed to do by analyzing the rest of the codebase: module names, signal connections, instantiations, comments, and usage patterns.

Follow these rules:

1. Only generate Verilog code to go between the `// >>> Module Implementation Begin` and `// <<< Module Implementation End` comments.
2. Use Verilog-2001 syntax. Ensure the code is synthesizable.
3. Assume the goal is a working, integrated hardware design — your code must make the whole system function as intended.
4. Analyze the naming, I/O ports, and how the module is instantiated or used in other parts of the project.
5. Implement correct behavior based on design context. Do not guess randomly — reason it out.
6. Avoid vendor-specific features unless explicitly required.
7. Do not output comments, explanation, or anything outside the required code region unless explicitly asked.

Your output should contain **only the Verilog code** that fits inside the marked region.

/*
 * Copyright (c) 2024 Jonny Edwards
 * SPDX-License-Identifier: Apache-2.0
 */

module tt_um_fountaincoder_top_ad (
    input  wire       clk,      // clock
    input  wire       ena,      // will go high when the design is enabled
    input  wire [7:0] ui_in,    // Dedicated inputs
    output wire [7:0] uo_out,   // Dedicated outputs
    input  wire [7:0] uio_in,   // IOs: Input path
    output wire [7:0] uio_out,  // IOs: Output path
    output wire [7:0] uio_oe,   // IOs: Enable path (active high: 0=input, 1=output)
    input  wire       rst_n     // reset_n - low to reset
);

// All output pins must be assigned. If not used, assign to 0.
assign uio_out = 8'b0;
assign uio_out = 8'b0;
assign uio_oe  = 8'b0;

PULSE pulse_count
(
	.clk (clk),
    .enable (ena),
    .reset (rst_n), 
    .pulse (ui_in),
	.gray_count (uo_out)
);
endmodule



// Gray counter

module PULSE
(
	input clk, enable, reset, 
	input [7:0] pulse,
	output reg [7:0] gray_count
);

reg [7:0] out_gray;
reg [3:0] pulse_count ;
reg count_enable;
GREY_COUNT gray
	(
		.clk (clk), 
		.enable (count_enable), 
		.reset (reset),
		.gray_count (out_gray)
	);

	

	always @ (posedge reset or posedge clk)
	begin
		if (reset) begin
			pulse_count <= 0;
		end
		else if (enable)
		begin
			if (pulse_count == 1) begin
				count_enable <= 1;
			end
			pulse_count <= pulse_count + pulse ;
			if (pulse_count > 3) begin
				gray_count <= out_gray;
				count_enable <= 0;
			end
			else begin 
				gray_count <= 0;
			end
		end
	end

endmodule


// Gray counter

module GREY_COUNT(
    input wire clk,
    input wire reset,
    input wire enable,
    output reg [7:0] gray_count
);
// >>> Module Implementation Begin

// <<< Module Implementation End
endmodule



Reference solution:
rtl/generated.v: 
    // q is the counter, plus the imaginary bit
    reg q [8:0]; // Adjusted to use positive indices
    
    // no_ones_below[x] = 1 iff there are no 1's in q below q[x]
    reg no_ones_below [8:0]; // Adjusted to use positive indices
    
    // q_msb is a modification to make the msb logic work
    reg q_msb;
    
    integer i, j, k;
    
    always @ (posedge reset or posedge clk)
    begin
        if (reset)
        begin
            // Resetting involves setting the imaginary bit to 1
            q[0] <= 1; // Adjusted index
            for (i = 1; i <= 8; i = i + 1) // Adjusted loop range
                q[i] <= 0;
        end
        else if (enable)
        begin
            // Toggle the imaginary bit
            q[0] <= ~q[0]; // Adjusted index
            // Additional logic to handle the rest of the bits
            for (i = 1; i <= 7; i = i + 1)
            begin
                // Flip q[i] if lower bits are a 1 followed by all 0's
                q[i] <= q[i] ^ (q[i-1] & no_ones_below[i-1]);
            end
            q[8] <= q[8] ^ (q_msb & no_ones_below[7]);
        end
    end
    
    always @(*)
    begin
        // There are never any 1's beneath the lowest bit
        no_ones_below[0] <= 1; // Adjusted index
        
        for (j = 1; j <= 8; j = j + 1) // Adjusted loop range
            no_ones_below[j] <= no_ones_below[j-1] & ~q[j-1];
        
        q_msb <= q[8] | q[7];
        
        // Copy over everything but the imaginary bit
        for (k = 0; k < 8; k = k + 1)
            gray_count[k] <= q[k+1]; // Adjusted index to skip the imaginary bit
    end