fakeha_s
Junior Member level 3
for loop
I am pasting part of my verilog code i converted the for loops if-else statements but the simulation were not as required ,i am making some mistake which i am unable to understand
code using for loop
for(a=63;a>=16;a=a-1)
begin //message4[a=63]inverted
//takes one bit of message4 converts it if check1 notequal to zero converts the bit
//to its original value and now inverts the next neighbouring bit a=62 and uses it in
//the nested for loop
message4[a]=~message4[a];
for(b=63;b>=0;b=b-1)
begin //this loop runs 63 times using the message4[a]
r2[16]=r2[15];
r2[15]=r2[14];
r2[14]=r2[13];
r2[13]=r2[12];
r2[12]=(r2[16]^r2[11]);
r2[11]=r2[10];
r2[10]=r2[9];
r2[9]=r2[8];
r2[8]=r2[7];
r2[7]=r2[6];
r2[6]=r2[5];
r2[5]=(r2[16]^r2[4]);
r2[4]=r2[3];
r2[3]=r2[2];
r2[2]=r2[1];
r2[1]=r2[0];
r2[0]=(message4 ^ r2[16]);
end
message4[a]=~message4[a];
cal_crc_code0=r2[16:1];
check1=cal_crc_code0^frame_crc_code;
r2=17'b0;
b=63;
if(check1==16'b0)
begin
error_bit=a;
message4[a]=~message4[a];
correctmessage=message4[63:16];
again=1;
end
//again is used further in code and makes
//a= 16 so that if at any point check1=0 the outer loop stops and no further
//calculation occurs if at any point
//check1 is not equal to zero outer loop continues from 63 to 16
end
code using if-else statements
if(a>=16)
begin
if(h==0)
message4[a]=~message4[a];
if(b>=0)
begin
h=1;
r2[16]=r2[15];
r2[15]=r2[14];
r2[14]=r2[13];
r2[13]=r2[12];
r2[12]=(r2[16]^r2[11]);
r2[11]=r2[10];
r2[10]=r2[9];
r2[9]=r2[8];
r2[8]=r2[7];
r2[7]=r2[6];
r2[6]=r2[5];
r2[5]=(r2[16]^r2[4]);
r2[4]=r2[3];
r2[3]=r2[2];
r2[2]=r2[1];
r2[1]=r2[0];
r2[0]=(message4 ^ r2[16]);
b=b-1;
if(b==-1)
begin
cal_crc_code0=r2[16:1];
check1=cal_crc_code0^frame_crc_code;
r2=17'b0;
b=63;
if(check1==16'b0)
begin
error_bit=a;
correctmessage=message4[63:16];
again=1;
b=0;
h=1;
end
else if(check1!=16'b0)
begin
message4[a]=~message4[a];
a=a-1;
h=0; //if check1 not equal to zero next message4 bit should be inverted
end
end
end
end
I am pasting part of my verilog code i converted the for loops if-else statements but the simulation were not as required ,i am making some mistake which i am unable to understand
code using for loop
for(a=63;a>=16;a=a-1)
begin //message4[a=63]inverted
//takes one bit of message4 converts it if check1 notequal to zero converts the bit
//to its original value and now inverts the next neighbouring bit a=62 and uses it in
//the nested for loop
message4[a]=~message4[a];
for(b=63;b>=0;b=b-1)
begin //this loop runs 63 times using the message4[a]
r2[16]=r2[15];
r2[15]=r2[14];
r2[14]=r2[13];
r2[13]=r2[12];
r2[12]=(r2[16]^r2[11]);
r2[11]=r2[10];
r2[10]=r2[9];
r2[9]=r2[8];
r2[8]=r2[7];
r2[7]=r2[6];
r2[6]=r2[5];
r2[5]=(r2[16]^r2[4]);
r2[4]=r2[3];
r2[3]=r2[2];
r2[2]=r2[1];
r2[1]=r2[0];
r2[0]=(message4 ^ r2[16]);
end
message4[a]=~message4[a];
cal_crc_code0=r2[16:1];
check1=cal_crc_code0^frame_crc_code;
r2=17'b0;
b=63;
if(check1==16'b0)
begin
error_bit=a;
message4[a]=~message4[a];
correctmessage=message4[63:16];
again=1;
end
//again is used further in code and makes
//a= 16 so that if at any point check1=0 the outer loop stops and no further
//calculation occurs if at any point
//check1 is not equal to zero outer loop continues from 63 to 16
end
code using if-else statements
if(a>=16)
begin
if(h==0)
message4[a]=~message4[a];
if(b>=0)
begin
h=1;
r2[16]=r2[15];
r2[15]=r2[14];
r2[14]=r2[13];
r2[13]=r2[12];
r2[12]=(r2[16]^r2[11]);
r2[11]=r2[10];
r2[10]=r2[9];
r2[9]=r2[8];
r2[8]=r2[7];
r2[7]=r2[6];
r2[6]=r2[5];
r2[5]=(r2[16]^r2[4]);
r2[4]=r2[3];
r2[3]=r2[2];
r2[2]=r2[1];
r2[1]=r2[0];
r2[0]=(message4 ^ r2[16]);
b=b-1;
if(b==-1)
begin
cal_crc_code0=r2[16:1];
check1=cal_crc_code0^frame_crc_code;
r2=17'b0;
b=63;
if(check1==16'b0)
begin
error_bit=a;
correctmessage=message4[63:16];
again=1;
b=0;
h=1;
end
else if(check1!=16'b0)
begin
message4[a]=~message4[a];
a=a-1;
h=0; //if check1 not equal to zero next message4 bit should be inverted
end
end
end
end