1 #!/usr/bin/perl 2 if ($ARGV >= 0) { 3 open(SRC,"$ARGV[0]") or die("ERROR:Please assign a source data file!!!!!!!!"); 4 }else{ 5 print("ERROR:Please assign a source data file!!!!!!!!"); 6 exit(); 7 } 8 open(DST,">$ARGV[0].18bit") || die("ERROR:Can't open output file"); 9 $line_num=0; 10 $cont=""; 11 while(<SRC>){ 12 $cont=$_; 13 $line_num++; 14 if($cont=~/\@([0-9A-Fa-f]+)\s+([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})/){ 15 $r1=$1; 16 $r2=hex($2); 17 $r3=hex($3); 18 $r4=$r2*512*2+$r3*2; 19 #print "$r4\n"; 20 $str=sprintf("%x",$r4); 21 if(length($str)==1) { 22 $align_str="0000".$str; 23 }elsif(length($str)==2){ 24 $align_str="000".$str; 25 }elsif(length($str)==3){ 26 $align_str="00".$str; 27 }elsif(length($str)==4){ 28 $align_str="0".$str; 29 }else{ 30 $align_str=$str; 31 } 32 printf DST "\@$r1 $align_str\n"; 33 }elsif($cont=~/([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})/){ 34 35 $r2=hex($1); 36 $r3=hex($2); 37 $r4=$r2*512*2+$r3*2; 38 #print "$r4\n"; 39 $str=sprintf("%x",$r4); 40 if(length($str)==1) { 41 $align_str="0000".$str; 42 }elsif(length($str)==2){ 43 $align_str="000".$str; 44 }elsif(length($str)==3){ 45 $align_str="00".$str; 46 }elsif(length($str)==4){ 47 $align_str="0".$str; 48 }else{ 49 $align_str=$str; 50 } 51 printf DST "$align_str\n"; 52 }else{ 53 print("ERROR:This line $line_num can't be understood!!\n"); 54 } 55 } 56 close(SRC); 57 close(DST); 58 59 print " Finished!!! \n ";