out2IMEM 1.18 KB
#!/usr/sbin/perl
#
$alt = 0;
$addr = 0;
$cnt = 0;
while (<>) {
  chop;
  split;

  if ($_[1] ne "") { $inst[$cnt++] = $_[1]; }
  if ($_[2] ne "") { $inst[$cnt++] = $_[2]; }
  if ($_[3] ne "") { $inst[$cnt++] = $_[3]; }
  if ($_[4] ne "") { $inst[$cnt++] = $_[4]; }

 }
for ($i = 0; $i<$cnt; $i++) {
	if ($alt==0) {
      	  printf "@%3.3X %8.8lX", $addr, hex($inst[$i]);
	  }
	else {
      	  printf "_%8.8lX", hex($inst[$i]);
	  printf "\t//addrs: 0x%3.3X  0x%3.3X",$addr*8, ($addr*8) + 4;
	  }
      if ($alt) {
        printf "\n";
	$addr = $addr+1;
      }
      $alt = !$alt;
    }

if ($addr == 0) {
     exit;
 }

if ($alt==1) {
printf "_%8.8lX", hex(0);
printf "\t//addrs: 0x%3.3X  0x%3.3X \n",$addr*8, ($addr*8) + 4;
}
else {
 $addr = $addr -1;
}

# fill with noops
if ($addr < 509) {
  $addr = $addr+1;
  printf "@%3.3X 00000000_00000000 \t//addrs: 0x%3.3X  0x%3.3X \n", 
	  $addr, $addr*8, ($addr*8) + 4;
}
if ($addr < 510) {
  $addr = $addr+1;
  printf "@%3.3X 00000000_00000000 \t//addrs: 0x%3.3X  0x%3.3X \n", 
	  $addr, $addr*8, ($addr*8) + 4;
}
if ($addr < 511) {
  $addr = $addr+1;
  printf "@%3.3X 00000000_00000000 \t//addrs: 0x%3.3X  0x%3.3X \n", 
	  $addr, $addr*8, ($addr*8) + 4;
}