module DEM_Reverse_64CH (
   input          clk            
  ,input  [6:0] msb_in   [63:0]
  ,input  [4:0] lsb_in   [63:0]
  ,input  	vld_in
  ,output reg	vld_out
  ,output reg [7:0] data_out [63:0]
);

reg [7:0] data_out_rr[63:0];
reg [7:0] data_out_r [63:0];
reg [1:0] vld_out_r;
genvar k;
generate

  for(k = 0; k < 32; k = k + 1) begin
    DEM_Reverse U_DEM_Reverse (
       .clk                   ( clk         )                      
      ,.therm_in              ( msb_in[k]   )
      ,.bin_in                ( lsb_in[k]   )
      ,.data_out              ( data_out_r[k] )
    );
  
  end

for(k = 32; k < 64; k = k + 1) begin
    DEM_Reverse U_DEM_Reverse (
       .clk                   ( ~clk        )                      
      ,.therm_in              ( msb_in[k]   )
      ,.bin_in                ( lsb_in[k]   )
      ,.data_out              ( data_out_r[k] )
    );
  
  end
 
endgenerate

generate

  for(k = 0; k < 64; k = k + 1) begin
    if(k<32) begin
      assign data_out[k] = data_out_r[k];
    end
    else begin
      assign data_out[k] = data_out_rr[k];
    end
  
  end
 
 
endgenerate


always @(posedge clk) begin
  data_out_rr <= data_out_r;
end

// \u5728\u65f6\u949f\u4e0a\u5347\u6cbf\u5bc4\u5b58\u8f93\u51fa
always @(posedge clk) begin
    vld_out_r <= {vld_out_r[0],vld_in};
end

assign vld_out = vld_out_r[1];
endmodule
