Showing posts with label Cross-assembler. Show all posts
Showing posts with label Cross-assembler. Show all posts

Wednesday, November 24, 2021

A List of Cross-Assemblers for Retrocomputing

 In my retrocomputing projects with various processors I have used a number of cross-assemblers to build code. I've had to use several in order to support different processors as well as for compatibility with different software packages. For the most part they are similar, but have their own unique features and quirks.

I put this table together, mostly for my own reference, that others may also find useful. It is by no means a complete list -- just those that I have used.

Name Author Source Supported Processors Key Features Comments
as9 Motorola, with changes by Albert van der Horst and others https://home.hccnet.nl/a.w.m.van.der.horst/m6809.html 6809 macros 100% compatible with Motorola assembler
asl Alfred Arnold and others http://john.ccac.rwth-aachen.de:8000/as/ many (over 50) Macros I have used with several processors
asm6809 Ciaran Anscomb https://www.6809.org.uk/asm6809/ 6809, 6309 macros Good choice if 6309 support needed.
cc65 John R. Dunning, Ullrich von Bassewitz, and others https://www.cc65.org/ 6502, 65C02 C compiler, assembler, linker, librarian Supports several 8-bit computer platforms.
crasm Leon Bottou https://github.com/colinbourassa/crasm 6800, 6801, 6803, 6502, 65C02, Z80 macros Included in most Linux distributions.
gcc Richard Stallman and others https://gcc.gnu.org/git/ Many Compilers and assemblers I used for 68000. Included in most Linux distributions.
lwasm William Astle and others http://lwtools.projects.l-w.ca/ 6809, 6309 Cross-assembler and linker. macros
vasmm68k_mot Volker Barthelmann http://sun.hasenbraten.de/vasm/ Many Cross-assembler I used for 68000.
z80asm Bas Wijnen http://savannah.nongnu.org/projects/z80asm Z80 Z80 cross-assembler Included in most Linux distributions.

Friday, February 8, 2019

A 6809 Single Board Computer: Cross-Compilers under Linux


Assembling code by hand is possible, but for any program of non-trivial size, cross-compilation is the way to go, even for 8-bit processors like the 6809. When working with my 6809 single board computer I went looking for a suitable cross-assembler. My requirements were to support the 6809, run on Linux, and be freely available. I came across three suitable programs, which I'll briefly describe here.

AS9 Assembler

Home page: http://home.hccnet.nl/a.w.m.van.der.horst/m6809.html

Documentation: http://home.hccnet.nl/a.w.m.van.der.horst/as11v2.pdf

This code is apparently derived from the original and official Motorola cross-assembler circa 1981. Written in very old pre-ANSI standard C, it was modified by a number of people over the years, and this version was last modified Albert van der Horst in 2004 to compile under Linux. I had no trouble building it under Ubuntu Linux.

As the official Motorola assembler, it follows the Motorola documentation. It seems pretty comprehensive, and supports the 6800, 6809, 68HC11, and some other chips in the 68xx series.

I have used this as my primary cross-assembler to develop or port the 6809 code I've been working on. The S-record files it generates are happily accepted by the ASSIST09 monitor's Load command.

Here is a sample output listing:

0005 7000                            ORG     $7000           ; Start address
0006                         
0007 7000 86 12              START:  LDA     #$12
0008 7002 c6 34                      LDB     #$34
0009 7004 8e 56 78                   LDX     #$5678
0010 7007 1e 89                      EXG     A,B
0011 7009 12                         NOP
0012 700a 12                         NOP
0013 700b 39                         RTS

The only quirk I encountered is a known issue where it can produce invalid warnings about comments. I worked around this when needed by disabling warnings with a command line option.

ASM6809 Assembler

Home page: https://www.6809.org.uk/asm6809

Documentation: https://www.6809.org.uk/asm6809/doc/asm6809.shtml

This is a portable cross assembler targeting the Motorola 6809 and Hitachi 6309 written by Ciaran Anscomb. It features arbitrarily complex expressions (with most C-style operators available), forward references, macro expansion and conditional assembly. Output formats are: raw binary, DragonDOS binary, Color Computer RS-DOS or "DECB" binary, Motorola S record, and Intel HEX.

Written in C, it is licensed under the GPL and is actively being maintained with the latest version being 2.11 released on 2018-07-27.

I downloaded the source and was able to build it with no problems simply by running the configure script, make, and sudo make install.

Trying it on my 6809 disassembler program (about 2000 lines of code), the only issues I encountered were that it didn't accept labels with a colon at the end and it didn't like one symbol I used that started with a dot. After making appropriate changes, the code built fine. It even warns that some long branches fit in eight bits and could have used short branches, so I modified them and made the code a little smaller. I did notice that it generated slightly different code than the as9 assembler had, where it picked a different (more efficient) indexed addressing mode that could use a 5-bit displacement.

Here is a sample listing:
                     
7000                          ORG     $7000           ; Start address
                      
7000  8612            START   LDA     #$12
7002  C634                    LDB     #$34
7004  8E5678                  LDX     #$5678
7007  1E89                    EXG     A,B
7009  12                      NOP
700A  12                      NOP
700B  39                      RTS

It generated a Motorola S record (RUN) file, but the ASSIST09 firmware did not like to load it. Investigation showed that it was producing S record files with invalid checksums. I made a code fix to the source for this. It also doesn't produce the S9 record at the end of the file that ASSIST09 wants to see, unless you have an END directory specifying that start address.

LWTOOLS

Home page: http://lwtools.projects.l-w.ca/

Documentation: http://lwtools.projects.l-w.ca/manual/manual.html

LWTOOLS is a set of cross-development tools for the Motorola 6809 and Hitachi 6309 microprocessors. It supports a number of output formats including raw binary, Motorola S record, Color Computer binaries, and a proprietary object file format that supports linking.

It is implemented in C and is actively maintained. I used version 4.16 that was released in December 2018.

It supports a number of platforms. I was able to build it with no issues on Ubuntu Linux. It installs a number of tools including lwasm, lwlink, lwar, and lwobjdump.

Here is a sample output listing:

                      (          ex1.asm):00005                 ORG     $7000           ; Start address
                      (          ex1.asm):00006         
7000 8612             (          ex1.asm):00007         START   LDA     #$12
7002 C634             (          ex1.asm):00008                 LDB     #$34
7004 8E5678           (          ex1.asm):00009                 LDX     #$5678
7007 1E89             (          ex1.asm):00010                 EXG     A,B
7009 12               (          ex1.asm):00011                 NOP
700A 12               (          ex1.asm):00012                 NOP
700B 39               (          ex1.asm):00013                 RTS

I only tried the assembler, using my disassembler program again. It didn't like items in FCB directives to be separated by any white space, only commas. It also didn't a like symbol starting with "." Other than that it assembled it fine, and generated a S record file which I successfully loaded and ran on the single board computer.

For advanced development work where you might want to assemble multiple files and link them, this looks like a good choice for a toolset. A 6809-based C compiler I have tried, CMOC, uses it as it's cross-assembler.

Summary

All three of these cross-assemblers look adequate for basic 6809 assembly language programming hosted on a Linux desktop. With a few changes I was able to get same source code for my disassembler to build with all three assemblers.

Saturday, July 8, 2017

Building a 68000 Single Board Computer - The Quelo 68000 Cross-Assembler

In the book 68000 Microcomputer Experiments by Alan D. Wilcox that I recently mentioned in a blog post, there is a chapter that covers using a cross-assembler to build 68000 code and upload it to the Motorola ECB. The assembler used for the examples is the Quelo 68000 cross-assembler.

A couple FORTH implementations for the 68000 that I came across mentioned that they were written for the Quelo assembler as well.

Quelo was a company based in Seattle, WA that offered a commercial cross-assembler for the 68000 that ran on CP/M and MS-DOS, around 1984. A Google search located a copy of the Quelo assembler for MS-DOS as well as a manual.


I was able to run the assembler under Linux using the dosbox MS-DOS emulator program (It likely runs under Windows 10 as well, but in my experience dosbox is often even more compatible with MS-DOS than recent versions of Windows are).

I used the small program example that was in the Wilcox book and was able to assemble it, generate an S record file, and upload and run it on my TS2 computer.

Assembling my larger calculator program generated some errors which looked trivial to fix (e.g. the syntax for PC relative addressing was different).

It looks like quite a sophisticated cross-assembler which includes macro support and a separate linker as well as some utilities like a cross-reference tool and utility for splitting files into odd and even ROMs.

All of the files I used as well as building instructions can be found here:
https://github.com/jefftranter/68000/tree/master/quelo.


A Google search for Quelo found a number of references to CP/M and Motorola 68K software including the ad above from the November 1983 issue of PC Magazine. The manual says it was licensed for a single user. One source referred to the CP/M version as being public domain; possibly they made the CP/M version of the assembler free when MS-DOS became more popular, but as far as I can tell the source code is not available anywhere and is likely lost.

It was fun to be able to run a program from 1983 on a modern computer, but for most of my 68000 cross-assembler needs I think I will stick to the VASM assembler which runs natively on Linux and is still being actively maintained.

Saturday, May 20, 2017

Building a 68000 Single Board Computer - Programming Examples


I earlier mentioned the book 68000 Assembly Language Programming, Second Edition, by Lance A. Leventhal, Doug Hawkins, Gerry Kane, and William D. Cramer. The book has many complete programming examples listed in it that help explain 68000 programming.

The book recommends entering and running the programs ona 68000-based system. I've been doing that, and it makes the code much clearer than simply reading the text. With the 68000 TUTOR software it is very easy to disassemble code in memory, display amd enter memory values, and run the program examples. I typically step through the code an instruction at a time using the trace function, looking at the values of the registers and selected memory locations.

Here is a typical disassembly of some example code:

TUTOR  1.3 > MD 4000 24 ;DI
004000    307C6001             MOVE.W  #24577,A0 
004004    7003                 MOVEQ.L #3,D0 
004006    4281                 CLR.L   D1 
004008    4282                 CLR.L   D2 
00400A    6008                 BRA.S   $004014 
00400C    D241                 ADD.W   D1,D1 
00400E    3601                 MOVE.W  D1,D3 
004010    E54B                 LSL.W   #2,D3 
004012    D243                 ADD.W   D3,D1 
004014    1418                 MOVE.B  (A0)+,D2 
004016    D242                 ADD.W   D2,D1 
004018    51C8FFF2             DBF.L   D0,$00400C 
00401C    33C100006004         MOVE.W  D1,$00006004 
004022    4E75                 RTS

While I could enter the programs as hex data from the text, or use TUTOR's built-in assembler, I have been entering the source code on a Linux computer and cross-assembling it using the VASM assembler. Then I can load the Motorola hex (run) file generated by the assembler into the TS2 computer over the serial port.

Here is the source code corresponding to the disassembly above:

DATA     EQU     $6000
PROGRAM  EQU     $4000
STRING   EQU     $6001           ADDRESS OF FOUR DIGIT BCD STRING
RESULT   EQU     $6004           ADDRESS OF RESULT
         ORG     PROGRAM
PGM_7_4A MOVEA.W #STRING,A0      POINTER TO FIRST BCD DIGIT
         MOVEQ   #4-1,D0         NUMBER OF DIGITS(-1) TO PROCESS
         CLR.L   D1              CLEAR FINAL RESULT - D1
         CLR.L   D2              CLEAR DIGIT REGISTER
         BRA.S   NOMULT          SKIP MULTIPLY FIRST TIME
LOOP     ADD.W   D1,D1           2X
         MOVE.W  D1,D3
         LSL.W   #2,D3           8X = 2X * 4
         ADD.W   D3,D1           10X = 8X + 2X
NOMULT   MOVE.B  (A0)+,D2        NEXT BCD DIGIT,(D2[15-8] UNCHANGED)
         ADD.W   D2,D1           ADD NEXT DIGIT
         DBRA    D0,LOOP         CONTINUE PROCESSING IF STILL DIGITS
         MOVE.W  D1,RESULT       STORE RESULT
         RTS
         END     PGM_7_4A

The VASM assembler is almost entirely compatible with the Motorola assembler and I have had to make only a very few changes to the code listed in the book. I did find a couple of errors, too.

So far I have entered almost four chapters worth of examples, just over thirty programs. I have placed the code on my github account. I'll continue doing so until I either get bored or finish the examples.

Sunday, March 30, 2014

The AS Macro Assembler

I was recently writing some Intel 8080 assembly language code for the Briel Altair 8800 computer. Assembling programs by hand and toggling in the binary codes using the front panel gets tedious very quickly. I could write it under CP/M and use the CP/M assembler, but text editing is a little clumsy under CP/M, the assembler is slow, and I want to run the programs standalone on the Altair 8800 without using CP/M.

A search for a cross-assembler that would run on Linux and support the Intel 8080 identified the AS macro assembler. This is a full-featured, free (GPL licensed) cross-assembler that runs on Linux and other desktop operating systems. It actually supports about 75 different microprocessors -- quite an amazing accomplishment!

I built it from source on Linux without any problems and was soon assembling 8080 assembly language code. The documentation that comes with it is very extensive and complete and the assembler listings are easy to read (some representative listing code is shown below).

727/     39F :                     ; GetAddress
728/     39F :                     ; Gets a four character hex number from the keyboard.
729/     39F :                     ; Ignores invalid characters. cancels and sets carry bit.
730/     39F :                     ; Returns binary word in HL.
731/     39F :                     ; Registers affected: A,B,H,L
732/     39F :                     
733/     39F :                     GetAddress:
734/     39F : CD 90 03                    call    GetByte         ; Get MSB
735/     3A2 : D8                          rc                      ; Exit if pressed
736/     3A3 : 67                          mov     h,a             ; Save MSB in H
737/     3A4 : CD 90 03                    call    GetByte         ; Get LSB
738/     3A7 : D8                          rc                      ; Exit if pressed
739/     3A8 : 6F                          mov     l,a             ; Save LSB in L
740/     3A9 : C9                          ret

It can produce Intel Hex format files which can be transferred to CP/M, converted to .COM files using the CP/M LOAD program, and then executed.

I am using it to generate a binary file which can be copied to an SD card and then directly loaded and executed by the firmware on the Briel Altair 8800.

It is very fast to assemble programs under Linux, and seems to have all the features and more than I could want. If you are looking for a good cross-assembler for the 8080 or just about any processor, it may be just what you need.