Today’s trip down memory lane includes looking into the 6809 CPU and its instruction set. It was the chip used on the Dragon 32/64 and TRS-80 Color (the original TRS-80 had a Z80).
There are tonnes of great resources on 8-bit computing, so my nostalgia for things 8-bit seems to be shared by others. This morning I came across the ASM6809 assembler written by Ciaran who also maintains the XRoar Dragon and TRS-80 Color emulator. It would not compile straight away on my Mac. Here are the problems which I’ve worked around for now and you can download the binaries here.
- The version of bison (a tool used to build parsers and compilers) supplied in Xcode is possibly one left by the Anglo-Saxons – i.e. it is slightly older. I’m going to install the latest using Homebrew.
- We need to persuade the build system to use the newer h files. I could adjust the Makefiles and configure infrastructure, but this morning I was in a hurry (as usual).
Here is the typescript which will build ASM6809 on an Intel Mac with Big Sur
# Install latest Bison brew install bison # Get the ASM6809 sources git clone https://www.6809.org.uk/git/asm6809.git # Setup to build cd asm6809 sh autogen.sh ./configure YACC=/usr/local/opt/bison/bin/bison DFLAGS="-L/usr/local/opt/bison/lib" # Make new grammar files cd src && make grammar.h cp grammar.tab.c grammar.c cp grammar.tab.h grammar.h # Build cd .. && make # Install make install
This outputs a binary and man page. You can download ASM6809 for Big Sur (Intel) here (use at your own risk, etc). Put this somewhere useful like /usr/local or your own personal bin and man directory. I suspect the above will work on Big Sur (Arm) but you may have to persuade the configure infrastructure of the target. I haven’t had time to test yet.
The provided test suite passes with the build (top marks to Ciaran for providing one) and a simple test works too (note that mnemonics must be indented with spaces or tabs for ASM6809 to work properly):
chris@MacMini% cat chris.s org $4000 lda #1 lda #3 ldx #4 rts chris@MacMini% asm6809 chris.s -o chris.o chris@MacMini% hexdump chris.o 0000000 86 01 86 03 8e 00 04 39 0000008
0x86 is the opcode for LDA, 0x8e is the opcode for LDX and 0x39 is the opcode for RTS. X is a 16-bit register on the 6809 and you can see here that 4 has been encoded into two bytes 00 & 04. I’ve spent the last two weeks on the 6502 CPU which has a similar instruction set to the 6809 and I forgot something about byte ordering for about a second. The 6809 is big-endian so it stores a 16-bit number high-byte first then low-byte. The 6502 is little-endian and would store them the other way round (04 first then 00). Anyway, all is good and the output is what it should be.
(Endian is a term that originated in Gulliver’s travels. The opinion was divided as to whether an egg should be eaten from the small or the big end, hence the Little-Endians and Big-Endians. There was much bloodshed.)
The Motorola 6809 image is used under a Creative Commons license.