Code: Select all
#! /usr/bin/perl
sub masm2std {
my ($label, $opcode, $operand, $comment) = @_;
$opcode = uc($opcode);
if ($opcode =~ /^(...)IM$/) {
$opcode = $1;
$operand = "#$operand";
}
elsif ($opcode =~/^(...)A([XY])$/) {
$opcode = $1;
$operand = "$operand,$2";
}
elsif ($opcode =~ /^(...)A$/) {
$opcode = $1;
$operand = 'A';
}
elsif ($opcode =~ /^(...)IX$/) {
$opcode = $1;
$operand = "($operand,X)";
}
elsif ($opcode =~ /^(...)IY$/) {
$opcode = $1;
$operand = "($operand),Y";
}
elsif ($opcode =~ /^(...)Z([XY])$/) {
$opcode = $1;
$operand = "$operand,$2";
}
elsif ($opcode eq 'JMI') {
$opcode = 'JMP';
$operand = "($operand)";
}
if (defined($comment)) {
printf("%-16s%-8s%-16s%s\n", $label, $opcode, $operand, $comment);
}
elsif (defined($operand)) {
printf("%-16s%-8s%s\n", $label, $opcode, $operand);
}
else {
printf("%-16s%s\n", $label, $opcode);
}
}
while (<>) {
chomp;
if (m/^\s*;/ || m/^\s*$/) {
print "$_\n";
}
elsif (m/^(\S+?)\s+(\S+?)\s+(.+?)\s*(;.*)$/) {
&masm2std($1, $2, $3, $4);
}
elsif (m/^(\S+?)\s+(\S+?)\s+(.*)$/) {
&masm2std($1, $2, $3, undef);
}
elsif (m/^(\S+?)\s+(.*)$/) {
&masm2std($1, $2, undef, undef);
}
elsif (m/^\s+(\S+?)\s+(.+?)\s*(;.*)$/) {
&masm2std(undef, $1, $2, $3);
}
elsif (m/^\s+(\S+?)\s+(.*)$/) {
&masm2std(undef, $1, $2, undef);
}
elsif (m/^\s+(.*)$/) {
&masm2std(undef, $1, undef, undef);
}
else {
print "$_\n";
}
}