Compiling Assembler programs for CP/M

Written June 21st, 2020 by

Let’s see an overview of assembler compilers and development environments to create programs for the CP/M operating system and in general for any machine with a Z80 microprocessor.

ASM

The ASM compiler supplied with the CP/M operating system is not particularly powerful but represents a good starting point.

Uses the Intel 8080 instructions only.

BDOS            EQU  05H
STROUT          EQU  09H

                ORG  0100H

ENTRY           LXI   D, HELLO
                MVI   C, STROUT
                CALL  BDOS
                RET

HELLO           DB   'Hello world!'
                DB   13, 10, '$'

                END

To obtain an executable program, it is necessary to compile the source with the ASM program which generates the Intel HEX code, followed by the LOAD program which reads the hexadecimal code and saves it in binary format ready to be executed.

asm-screen

 

Microsoft Macro Assembler

For more complex programs, the Microsoft compiler offers several advanced features, among which the possibility to compile different sources and link them together to generate a single program, but above all the compatibility with the Z80 instructions and syntax.

		.Z80

BDOS            EQU  05H
STROUT          EQU  09H

		CSEG

ENTRY:          LD    DE, HELLO
                LD    C, STROUT
                CALL  BDOS
                RET

		DSEG

HELLO:          DB   'Hello world!'
                DB   13, 10, '$'

                END  ENTRY

To obtain an executable program, you need to compile the source with the M80 program which generates an object file, followed by the L80 program which reads the code contained in the object file and saves it in binary format ready to be executed.

m80-screen

 

TASM

This is a DOS program capable of compiling assembler sources for various microprocessors including the 8080 and Z80. To use it you need Windows or an emulator like DOSBOX.

The syntax of the source is slightly different from the previous ones, but being compatible with the 8080 and Z80 instructions, porting is very easy.

BDOS            .EQU  05H
STROUT          .EQU  09H

                .ORG  100H

ENTRY           LD    DE, HELLO
                LD    C, STROUT
                CALL  BDOS
                RET

HELLO           .DB   "Hello world!"
                .DB   13, 10, "$"

                .END

The compiler directly generates the binary file which will then be copied to the CP/M machine in some way.

tasm-screen

 

Z80 Tools

This is the development environment I created to develop assembler software for the Z80. It includes an editor with syntax highlighting, a compiler, an integrated debugger and an emulator. It allows you to interface directly with a CP/M machine via the serial port and upload programs in a format compatible with the DOWNLOAD.COM program or via XMODEM.

z80-tools-screen

 

Links