Compiling 16-bit Code for the SYSC 3601/ELEC 4601 Lab

As time has marched on, it's a little bit tricky to produce code that will run on a raw 8086, as used in our lab. Luckily Microsoft has left enough scraps of their assembler laying around for public use that one can cobble together a (legal!) solution. Of course this won't help you test your code for the labs where you have to interface with the various chips and devices on the board, but it's helpful if your code at least compiles when you come to the lab.

UPDATE: Check the Problems section for info on common issues.

Obtaining MASM

The maintenance of the 32-bit verison of MASM has been taken over by groups on the internet, as Microsoft has largely discontinued active development.

MASM32 can be obtained here. Note the very first link is the Canadian mirror. Extract the file and run install.exe, which will install an editor and many extra libraries for 32-bit Windows assembly coding on your system, most of which we are not interested in.

The important files will be in c:\masm32\bin. MASM.exe has been renamed ML.exe at some point over the years, and is the assembler executable. LINK.exe is still the linker, but we need to replace it with a 16-bit linker in order to generate code appropriate for the board in the labs.

A 16-bit linker can be downloaded from Microsoft. It will extract three files when executed, the important one being LINK.exe. Copy this into c:\masm32\bin. If you want to retain the option of using the 32-bit linker, rename it to LINK32.exe or similar before overwriting it.

Using MASM

The simplest thing to do is just copy ML.exe and LINK.exe into the directory you want to work in. You can try using the QEditor GUI provided in the install package, but we can't help you if you have problems. So, assuming you're working from the command line in a directory containing the two executables and your source files, here are some things you'll need to know:

  1. Every source file you create should have a line with .8086 at the top, in order to create only instructions for the 8086. (Note, this may change slightly for Lab 4, we'll let you know).
  2. Some of the labels used in the code cause problems because they are reserved keywords for newer versions of the assembler that support newer processors. To make sure only the 8086 instructions are recognized, pass the parameter /Zm. If you encounter further problems with reserved words (note: LOOP and STR are reserved), please use a different label. This will most often manifest itself as a

    error A2008: syntax error

    referring to the following token in the file.
  3. If you invoke:

    ml.exe /Zm filename.asm

    it will automatically run the linker for you and produce an executable (if there are no errors). If you for some reason only want to assemble your code to an object file, pass the parameter /c, as in:

    ml.exe /Zm /c filename.asm

  4. If you would like to produce a file listing the assembled instructions next to their source code equivalents (along with some information on the memory layout), pass the parameter /Flfilename.lst, as in:

    ml.exe /Zm /Flfilename.lst /c filename.asm

Problems?