A18 Assembler for COSMAC


Introduction to the A18 Assembler for COSMAC

The A18 Assembler for COSMAC will convert your COSMAC assembly programs to object code. After that, you can send the file to your processor. I’m using Debian 11 for this example, but the A18 package also comes with a .exe file if you are stuck with Windows. Keep in mind this is a command line tool. There is no graphical interface. It simply converts a text file (with .asm extension) to object code. The flags I use in this example will give you both a LIST file (.lst), and a HEX file (.hex). The List file is helpful for troubleshooting, while the HEX file is what you send to your COSMAC.

Assembly language makes programming easier, because you don’t need to remember the OPCODE for each instruction. You enter the code in the form of mnemonics. For example, to load the value of 70 to the D register, you just type LDI 70H instead of F8 70. In the COSMAC, your D register is similar to the Accumulator in other processors. For a list of instructions and OPCODES, you can check out the COSMAC 1802 User Manual.

As always, we need to be thankful for those who have worked to create and maintain this code. Without their work, you would be entering the whole program through your keypad, and have to look up each OPCODE individually.

I’m using the COSMAC CDP1802 Microprocessor kit for this example.

This is William Coley’s assembler with modifications by Herb Johnson. You can download the A18 Assembler from his web page.

Setting up the A18 Assembler for COSMAC

After you download, simply extract the files. My preference was to place the a18 folder into my home folder. Since this is a command line too, you will want it to be in a place that’s easy to get to.

For Linux, you will want to be sure to install the GCC compiler. After that, there are a few things we need to do to get set up. The instructions are in the file “a18_linux.txt”. There are only a few steps. If you are running Windows, you can skip down to the section “Compiling your Code with the A18 Assembler for COSMAC”

1) First, we’ll create a symlink. ln -s A18.H a18.h I got an error that the file already exists when running this command. I believe the idea of this line is to make it available in both upper and lower case. I simply reversed the source and destination, then ran it again to make sure you can locate the file both ways.

Now, we need to compile the assembler

2) gcc -I. -o a18 a18.c a18util.c a18eval.c

3) To check for errors: gcc -o a18 a18.c a18eval.c a18util.c -Wall 2>wallerrors.txt

4) Finally, we’ll create a shell script. This will be the script we use to run the compiler. I simply typed “vi asm18”, then press “i” for insert. You could use nano too if that is the editor you prefer.

Add the following code

#!/bin/bash

./a18 $1.asm -l $1.lst -o $1.hex

Finally, save your work. In VI, just type “:wq”. In nano, just CTRL-X and save.

5) Next, I made the script executable: chmod +x asm18

Compiling your Code with the A18 Assembler for COSMAC

At last, we are ready to compile your code. We’ll assume you already have written your code in assenbly. In this case, I’ve saved the file as timer2.asm (asm is lower case).

Keep in mind that our script will look for a file with the lower case “asm” extension. It will automatically create the lst file, and the hex file.

To assemble our code using Linux, I’ll just type: ./asm18 timer2 To clarify: (dot slash asm18 (space) timer2) I’m specifying asm18 because that is the name of the script we created in the last section.

If you run windows, just navigate to the a18 directory and type “a18 timer2”.

As you can see, the code compiled with no errors.

Let’s look at the directory again. As you can see, we now have timer2.lst, and timer2.hex as well.

Send your File to the COSMAC

At this point, you are ready to send your file to the COSMAC. If you use Linux, a good program is minicom. For Windows, a good terminal is TeraTerm. Just be sure to set your character and line feed delays. 10ms is usually a good delay time for each. Be sure to connect to your COSMAC.

Open your hex file with a standard text editor. The object code is in the INTEL HEX file format. Each line ends with a checksum. The last line indicates the end of the file. Set your COSMAC to receive the file, and then paste the object code into your terminal emulator.

At this point set your program counter to the start of the user program and place your processor into run mode.

For more information, visit the Vintage Computer Category Page!

— Ricky Bryce

For Customized automation training, visit my employer's website at http://atifortraining.com!

Leave a comment

Your email address will not be published. Required fields are marked *

  +  sixty  =  63