Hello CP/M z80-world

Actually I don’t know how I ended up exploring CP/M, and that is probably a story in itself. But here I am, summarizing my experiences from getting CP/M up and running on an Altair simulator and writing Hello World in z80 assembly.

Getting the environment up and running

The simulator altairz80 and cpm2 disk images can be obtained from this URL: http://cpmarchives.classiccmp.org/cpm/mirrors/www.schorn.ch/cpm/intro.php

I was never a user of these systems back in the days. I had a ZX/Spectrum and went directly from that to IBM PC. So this universe is kind of new to me.

Entering Altair 8800 command line by running the command altairz80 and booting up CP/M with the command: do cpm2.

What’s next – Hello World!

I have not so much to do in CP/M but write a hello world program. Some searching on the Internet how to get a string printed on the console ended me up with BDOS function #9.

Getting into the editor was my biggest learning. The ed command is not really intuitive, but eventually I succeeded in creating my program.

Looking at the code below, here I am instructing the assembler that I will be using z80 assembly. The BDOS interrupt is 5 and the function is 9 as above. The code shows that register c holds the value 9 and de points to MSG as instructed.

hello.asm

Let’s run the assembler. Not very informative, but at least it does not find any fatal errors.

It creates a list file that looks like this. It makes my head spin when I see that it is the macro assembler that dates back to December 9, 1981.

Linking and creating the executable. Good to see that 47138 bytes are free. Memory was not unlimited back in 1981.

So now a hello.com file is created since there are no obvious errors. Let’s run it.

Mission accomplished. But let’s look at the debugger. Running the command: ddt hello.com, we see the machine code.

The string “Hello world!” starts at address 103. The program starts with a jump to 112, where we below can see that 9 is loaded into C and 103 (with the beginning of the string) is loaded into d. Then a call to 5, the BDOS function.

What did I just learn?

Maybe nothing that is of really practical use for me in my professional life. But being an IT professional, I feel very humble when I look at everything we take for granted in our daily work.

I actually found myself enjoying reading the programmer’s guides from early 80s. They were written and created in an era when the Internet was not available, and I can more or less feel the eagerness to transfer knowledge to the reader, answering the questions that might arise, because there was not that easy to collaborate and ask questions.

I just realized that I need to get CP/M 86 for the PC up and running, so that will be a later post.


Posted

in

by

Comments

Leave a comment

Design a site like this with WordPress.com
Get started