lst2IMEM 1.15 KB
#!/usr/sbin/perl
# SCCS: @(#)MAKE_IHEX   1.1 07 Sep 1994
#
#
# This program extracts the instructions in ascii hex format from
# the .lst file which is an output of the rspasm.
#
$alt = 0;
$addr = 0;
while (<>) {
  chop;
  split;
  if ($_ ne "") {
    if ($_[0] ne "***") {
	if ($alt==0) {
      	  printf "@%3.3X %8.8lX", $addr, hex($_[2]);
	  }
	else {
      	  printf "_%8.8lX", hex($_[2]);
	  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;
}