OpenCores
URL https://opencores.org/ocsvn/lattice6502/lattice6502/trunk

Subversion Repositories lattice6502

[/] [lattice6502/] [ghdl/] [asm2bin.pl] - Rev 4

Compare with Previous | Blame | View Log

#!/usr/bin/perl
#	This and asm2bin converts asm file foo.asm into rom files.
#	1st type foo.bin used with ghld roms
#	2nd type foo.mem used with Lattice roms
#	This perl script call crasm to do the assembly.
#	crsasm generates the program listing foo.lst
 
$name = "$ARGV[0]";
#	The program was compilled at start address
$progadd = hex("FC00");
#	The code is packed into ROM start address
$romadd = hex("0");
$romsize = 1024;
#	was 128
$add_delta = $romadd - $progadd;
 
print "Processing $name.asm \n";
#	run crasm to generate *.o and *.lst
`crasm -o $name.o -x $name.asm > $name.lst`;
 
open(OBJfile, "< $name.o");
open(BINfile, "> $name.bin");
 
$n = 0;
@file = <OBJfile>;
 
foreach $line (@file)	{
	if (substr($line, 0, 2) = "S1") {
		$bytes = hex(substr($line, 2, 2));
			$HEXadd = substr($line, 4, 4);
			$address = hex("$HEXadd");
			$runningadd = $address + $add_delta;
			$len = length($line);
			$substring = substr($line, 8, ($len-11));
		print "$line";
		print "n = $n, Address = $address, runAddress = $runningadd, del =  $add_delta \n";
 
			while ($n < $runningadd) {
					print (BINfile "X\"EA\", \n");
					$n++;
					print("n is $n \n");
					}
 
		$a = 0;
#		while ($a < ($len - 11)) {
		while ($a < ($len - 11) and ($address > 64511)) {
			$byte = substr($substring, $a, 2);
			if ($n eq ($romsize - 1)) {
				print (BINfile "X\"$byte\" )  ; \n");				
			}
			else	{
				print (BINfile "X\"$byte\", \n");
				}
			$a = $a + 2;
			$n++ ;
			}
		}
	}
 
 
close(OBJfile);
close(BINfile);
 
#	end
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.