Subject: Re: A 6809 disassembler
From: charste@summit (Charles Stevens)
Date: Tue, 27 Jul 1993 21:59:57 GMT
Newsgroups: comp.sys.m6809

[email-masked] (Desnogues) writes:
: Can someone tell me where I can get a disassembler for the
: Motorola 6809 in C ? I already have dis09 which is written
: in ... 6809. Can't really use it :-)
: 
: 		Laurent Desnogues

How about half a disassembler written in Perl?? (Only about 2 hours work --
mostly typing in the instruction set.  Still needs support for multi-byte 
op-codes.  This was actually written for the 68HC11 and if you choose to modify
it will give an idea of how differnt the 11 and 09 really are.  Well here it is
.. don't laugh to hard :-) 

---------------------8<---Cut here--------8<----------------------------------

#!/usr/local/bin/perl

# Use the file they specified, if specified

open(STDIN,$ARGV[0]) || die "Can't open $ARGV[0]: $!\n"
    if $ARGV[0];

%formats = (
    'dd mm rr', "%4.4X %2.2X %2.2X %2.2X %2.2X %s \$%2.2X,#\$%2.2X,\$%4.4X\n",
    'ff mm rr', "%4.4X %2.2X %2.2X %2.2X %2.2X %s \$%2.2X,X,\$%2.2X,\$%4.4X\n",
    'dd mm',    "%4.4X %2.2X %2.2X %2.2X   %s \$%2.2X,#\$%2.2X\n",
    'ff mm',    "%4.4X %2.2X %2.2X %2.2X   %s \$%2.2X,X \$%2.2X\n",
    'jj kk',    "%4.4X %2.2X %2.2X %2.2X   %s #\$%2.2X%2.2X\n",
    'hh ll',    "%4.4X %2.2X %2.2X %2.2X   %s \$%2.2X%2.2X\n",
    'rr',       "%4.4X %2.2X %2.2X     %s \$%4.4X\n",
    'dd',       "%4.4X %2.2X %2.2X     %s \$%2.2X\n",
    'ii',       "%4.4X %2.2X %2.2X     %s #\$%2.2X\n",
    'ff',       "%4.4X %2.2X %2.2X     %s #\$%2.2X,X\n",
    '',		"%4.4X %2.2X        %s\n",
);

# init the array of OpCodes

@map = (
	"TEST",
	"NOP",
	"IDIV",
	"FDIV",
	"LSRD",
	"ASLD",
	"TAP",
	"TPA",
	"INX",
	"DEX",
	"CLV",
	"SEV",
	"CLC",
	"SEC",
	"CLI",
	"SEI",
	"SBA",
	"CBA",
	"BRSET dd mm rr",
	"BRCLR dd mm rr",
	"BSET dd mm",
	"BCLR dd mm",
	"TAB",
	"TBA",
	"(Page2)",
	"DAA",
	"(Page3)",
	"ABA",
	"BSET ff mm",
	"BCLR ff mm",
	"BRSET ff mm rr",
	"BRCLR ff mm rr",
	"BRA rr",
	"BRN rr",
	"BHI rr",
	"BLS rr",
	"BCC rr",
	"BCS rr",
	"BNE rr",
	"BEQ rr",
	"BVC rr",
	"BVS rr",
	"BPL rr",
	"BMI rr",
	"BGE rr",
	"BLT rr",
	"BGT rr",
	"BLE rr",
	"TSX",
	"INS",
	"PULA",
	"PULB",
	"DES",
	"TSX",
	"PSHA",
	"PSHB",
	"PULX",
	"RTS",
	"ABX",
	"RTI",
	"PSHX",
	"MUL",
	"WAI",
	"SWI",
	"NEGA",
	"FCB aa",
	"FCB aa",
	"COMA",
	"LSRA",
	"FCB aa",
	"RORA",
	"ASRA",
	"ASLA",
	"ROLA",
	"DECA",
	"FCB aa",
	"INCA",
	"TSTA",
	"FCB aa",
	"CLRA",
	"NEGB",
	"FCB aa",
	"FCB aa",
	"COMB",
	"LSRB",
	"FCB aa",
	"RORB",
	"ASRB",
	"LSLB",
	"ROLB",
	"DECB",
	"FCB aa",
	"INCB",
	"TSTB",
	"FCB aa",
	"CLRB",
	"NEG ff",
	"FCB aa",
	"FCB aa",
	"COM ff",
	"LSR ff",
	"FCB aa",
	"ROR ff",
	"ASR ff",
	"ASL ff",
	"ROL ff",
	"DEC ff",
	"FCB aa",
	"INC ff",
	"TST ff",
	"JMP ff",
	"CLR ff",
	"NEG hh ll",
	"FCB aa",
	"FCB aa",
	"COM hh ll",
	"LSR hh ll",
	"FCB aa",
	"ROR hh ll",
	"ASR hh ll",
	"ASL hh ll",
	"ROL hh ll",
	"DEC hh ll",
	"FCB aa",
	"INC hh ll",
	"TST hh ll",
	"JMP hh ll",
	"CLR hh ll",
	"SUBA ii",
	"CMPA ii",
	"SBCA ii",
	"SUBD jj kk",
	"ANDA ii",
	"BITA ii",
	"LDAA ii",
	"FCB aa",
	"EORA ii",
	"ADCA ii",
	"ORAA ii",
	"ADDA ii",
	"CPX jj kk",
	"BSR rr",
	"LDS jj kk",
	"XGDX",
	"SUBD dd",
	"CMPA dd",
	"SBCA dd",
	"SUBD dd",
	"ANDA dd",
	"BITA dd",
	"LDAA dd",
	"STAA dd",
	"EORA dd",
	"ADCA dd",
	"ORAA dd",
	"ADDA dd",
	"CPX dd",
	"JSR dd",
	"LDS dd",
	"STS dd",
	"SUBA ff",
	"CMPA ff",
	"SBCA ff",
	"SUBD ff",
	"ANDA ff",
	"BITA ff",
	"LDAA ff",
	"STAA ff",
	"EORA ff",
	"ADCA ff",
	"ORAA ff",
	"ADDA ff",
	"CPX ff",
	"JSR ff",
	"LDS ff",
	"STS ff",
	"SUBA hh ll",
	"CMPA hh ll",
	"SBCA hh ll",
	"SUBD hh ll",
	"ANDA hh ll",
	"BITA hh ll",
	"LDAA hh ll",
	"STAA hh ll",
	"EORA hh ll",
	"ADCA hh ll",
	"ORAA hh ll",
	"ADDA hh ll",
	"CPX hh ll",
	"JSR hh ll",
	"LDS hh ll",
	"STS hh ll",
	"SUBB ii",
	"CMPB ii",
	"SBCB ii",
	"ADDD jj kk",
	"ANDB ii",
	"BITB ii",
	"LDAB ii",
	"FCB aa",
	"EORB ii",
	"ADCB ii",
	"ORAB ii",
	"ADDB ii",
	"LDD jj kk",
	"(Page4)",
	"LDX jj kk",
	"STOP",
	"SUBB dd",
	"CMPB dd",
	"SBCB dd",
	"ADDD dd",
	"ANDB dd",
	"BITB dd",
	"LDAB dd",
	"STAB dd",
	"EORB dd",
	"ADCB dd",
	"ORAB dd",
	"ADDB dd",
	"LDD dd",
	"STD dd",
	"LDX dd",
	"STX dd",
	"SUBB ff",
	"CMPB ff",
	"SBCB ff",
	"ADDD ff",
	"ANDB ff",
	"BITB ff",
	"LDAB ff",
	"STAB ff",
	"EORB ff",
	"ADCB ff",
	"ORAB ff",
	"ADDB ff",
	"LDD ff",
	"STD ff",
	"LDX ff",
	"STX ff",
	"SUBB hh ll",
	"CMPB hh ll",
	"SBCB hh ll",
	"ADDD hh ll",
	"ANDB hh ll",
	"BITB hh ll",
	"LDAB hh ll",
	"STAB hh ll",
	"EORB hh ll",
	"ADBC hh ll",
	"ORAB hh ll",
	"ADDB hh ll",
	"LDD hh ll",
	"STD hh ll",
	"LDX hh ll",
	"STX hh ll",
);

$offset = 0xA000;

# $idx -- index into opcode map
# @inst -- instruction template for dis-assembler
# $mn_inst -- mnemonic form of the instruction

while (($len = read(STDIN,$data,1)) == 1) 
{
    $idx = unpack('C1', $data);
    @inst = split(" ", $map[$idx]);
    read(STDIN, $data2, $#inst);
    @args = unpack("C$#inst", $data2);
    if ($rel = ($inst[$#inst] =~ 'rr'))
    {
	@args2 = unpack("c$#inst", $data2);
	$args2[$#args] = $offset + @inst + $args2[$#args2];
    }
    $mn_inst = shift(@inst);
    $fmt = $formats{join(" ",@inst)};
    printf($fmt, $offset, $idx, @args, $mn_inst, ($rel == 0) ? @args: @args2);
    $offset += @inst + 1;
}

---------------------8<---Cut here--------8<----------------------------------

Also another thread asked about free C for the 09.  I know that GNU C has 
been aimed at the 09, can someone please post the location?

-----------------------------------------------------------------------------
Charles H. Stevens                     | [email-masked]
Senior Technical Support Specialist    |
Rosemount Inc. (M.S. PE-03)            |
8200 Market Blvd.                      | voice (612) 949-7461 
Chanhassen, MN 55317                   | fax   (612) 949-7626