module secded_ecc8(
input logic [7:0] data_in,input logic [12:0] code_in,
output logic [12:0] code_out,output logic [7:0] data_out,
output logic single_error,double_error,corrected,output logic [3:0] syndrome);
logic [12:0] c,fixed_c; logic overall;
always_comb begin
 code_out='0;
 code_out[2]=data_in[0];code_out[4]=data_in[1];code_out[5]=data_in[2];code_out[6]=data_in[3];
 code_out[8]=data_in[4];code_out[9]=data_in[5];code_out[10]=data_in[6];code_out[11]=data_in[7];
 code_out[0]=code_out[2]^code_out[4]^code_out[6]^code_out[8]^code_out[10];
 code_out[1]=code_out[2]^code_out[5]^code_out[6]^code_out[9]^code_out[10];
 code_out[3]=code_out[4]^code_out[5]^code_out[6]^code_out[11];
 code_out[7]=code_out[8]^code_out[9]^code_out[10]^code_out[11];
 code_out[12]=^code_out[11:0];
 c=code_in;fixed_c=code_in;
 syndrome[0]=c[0]^c[2]^c[4]^c[6]^c[8]^c[10];
 syndrome[1]=c[1]^c[2]^c[5]^c[6]^c[9]^c[10];
 syndrome[2]=c[3]^c[4]^c[5]^c[6]^c[11];
 syndrome[3]=c[7]^c[8]^c[9]^c[10]^c[11];
 overall=^c;single_error=0;double_error=0;corrected=0;
 if(overall) begin single_error=1;corrected=1;
  if(syndrome==0) fixed_c[12]=~fixed_c[12];
  else if(syndrome<=12) fixed_c[syndrome-1]=~fixed_c[syndrome-1];
 end else if(syndrome!=0) double_error=1;
 data_out={fixed_c[11],fixed_c[10],fixed_c[9],fixed_c[8],fixed_c[6],fixed_c[5],fixed_c[4],fixed_c[2]};
end
endmodule
