The Z88DK C Cross Compiler

232 views
Skip to first unread message

Frank P.

unread,
Jul 18, 2020, 7:18:05 PM7/18/20
to altair...@googlegroups.com
I recently discovered a C cross compiler that runs on Windows/Linux/Mac and can generate .COM files to run under CP/M. This is Z88DK (see https://www.z88dk.org/forum/ and https://github.com/z88dk/z88dk). When I first discovered it a couple weeks ago, it could generate code for a Z80 processor but not 8080. But many of the issues with the 8080 compiler and libaray have been fixed now. I used this to compile slightly modified versions of my PI.C and PI-OL.C programs (see PI as a Benchmark). As a result I was able to generate .COM files for the two PI programs that run approximately twice as fast as the Aztec C generated executables on the AltairDuino in 8080 CPU mode, and approximately 4 times faster than the Aztec C generated executables on the AltairDuino in Z80 CPU mode. The reason for the difference in speeds between 8080 and Z80 is that Z88DK comprises two different compilers (one older, one newer) and two different libraries (one older, one newer). The newer compiler and library are heavily optimized for the Z80 and can't be used to generate 8080 executables. The older compiler and library can generate 8080 code, but at the expense of speed. Much of the Z80 code speed revolves around the Z80 index registers, not present on the 8080.

So, for your experimentation, attached (in a .ZIP file) are the two C programs for computing PI, compilable with Z88DK, plus the 4 executable .COM files (2 for 8080/Z80, 2 for Z80 only), plus 4 Windows/DOS batch files that generate the 4 .COM files. These files are:

PIZ88.C           - PI.C modified to compile with Z88DC
PIZ8080.COM       - Executable for PIZ88.C compiled for the 8080
PIZ88.COM         - Executable for PIZ88.C compiled for the Z80
PIZ8080.BAT       - Windows/DOS batch file to compile PIZ88.C for the 8080
PIZ88.BAT         - Windows/DOS batch file to compile PIZ88.C for the Z80

PI-OLZ88.C        - PI-OL.C modified to compile with Z88DC
PIOZ8080.COM      - Executable for PI-OLZ88.C compiled for the 8080
PI-OLZ88.COM      - Executable for PI-OLZ88.C compiled for the Z80
PIOZ8080.BAT      - Windows/DOS batch file to compile PI-OLZ88.C for the 8080
PI-OLZ88.BAT      - Windows/DOS batch file to compile PI-OLZ88.C for the Z80

Sorry for the somewhat confusing file names - you can only do so much with 8 characters.

If you download Z88DK, make sure you get the July 17, 2020 nightly build or later - earlier builds did not have the necessary fixes and optimizations for generating 8080 code. It's not tough to install on Windows, you just plunk the z88dk directory down somewhere and set up a couple of environment variables to point to it. You run it at a DOS Command Prompt (CMD), or just use the included batch files for the PI variations.

Enjoy!
PIforZ88DK.zip
Message has been deleted
Message has been deleted
Message has been deleted

Frank P.

unread,
Jul 18, 2020, 7:26:24 PM7/18/20
to altair...@googlegroups.com
Google Groups is giving me fits trying to attach a zip file. You can get it from here too: PIforZ88DK
OK, that works!!!

On Saturday, July 18, 2020 at 7:18:05 PM UTC-4, Frank P. wrote:
I recently discovered a C cross compiler that runs on Windows/Linux/Mac and can generate .COM files to run under CP/M. This is Z88DK (see https://www.z88dk.org/forum/ and https://github.com/z88dk/z88dk). When I first discovered it a couple weeks ago, it could generate code for a Z80 processor but not 8080. But many of the issues with the 8080 compiler and libaray have been fixed now. I used this to compile slightly modified versions of my PI.C and PI-OL.C programs (see PI as a Benchmark). As a result I was able to generate .COM files for the two PI programs that run approximately twice as fast as the Aztec C generated executables on the AltairDuino in 8080 CPU mode, and approximately 4 times faster than the Aztec C generated executables on the AltairDuino in Z80 CPU mode. The reason for the difference in speeds between 8080 and Z80 is that Z88DK comprises two different compilers (one older, one newer) and two different libraries (one older, one newer). The newer compiler and library are heavily optimized for the Z80 and can't be used to generate 8080 executables. The older compiler and library can generate 8080 code, but at the expense of speed. Much of the Z80 code speed revolves around the Z80 index registers, not present on the 8080.

So, for your experimentation, attached (in a .ZIP file) are the two C programs for computing PI, compilable with Z88DK, plus the 4 executable .COM files (2 for 8080/Z80, 2 for Z80 only), plus 4 Windows/DOS batch files that generate the 4 .COM files. These files are:

PIZ88.C           - PI.C modified to compile with Z88DC
PIZ8080.COM       - Executable for PIZ88.C compiled for the 8080
PIZ88.COM         - Executable for PIZ88.C compiled for the Z80
PIZ8080.BAT       - Windows/DOS batch file to compile PIZ88.C for the 8080
PIZ88.BAT         - Windows/DOS batch file to compile PIZ88.C for the Z80

PI-OLZ88.C        - PI-OL.C modified to compile with Z88DC
PIOZ8080.COM      - Executable for PI-OLZ88.C compiled for the 8080
PI-OLZ88.COM      - Executable for PI-OLZ88.C compiled for the Z80
PIOZ8080.BAT      - Windows/DOS batch file to compile PI-OLZ88.C for the 8080
PI-OLZ88.BAT      - Windows/DOS batch file to compile PI-OLZ88.C for the Z80

I'm having trouble attaching the .ZIP file, so I will attach it in a separate post.

Frank P.

unread,
Mar 28, 2021, 9:30:21 AM3/28/21
to Altair-Duino
Off topic I know, but if you're interested, here are my versions of these PI programs for a TI-83 calculator, both in TI-BASIC 83 and C over in the retro-comp google group:

fred_...@hotmail.com

unread,
May 19, 2021, 1:53:08 PM5/19/21
to Altair-Duino
Frank

What I find utterly fascinating is how well HI-TECH 3.09 holds up! Sure, it can be improved on -- but it takes an order of magnitude more resources to get a couple of percent improvement. Now... were I to use Z80 for a project, I would probably use HI-TECH 3.09 (in cross compile mode using zxc). With a bit of (either) in-line assembler or zas, we can do most of what is needed.

HI-TECH C code generation is pretty good -- for 8080 use, you *may* want to consider Whitesmiths C 2.1 *That* compiler gives
good results for 8080.

What I did notice is that your C code does *not* have any "register" directives. As compiler hints, this is vital for the best code
generation for boh HI-TECH and Whitesmiths.  HI-TECH has only a single "register" Whitesmiths has 1.5 (uses BC and DE very effectively).

I don't have time to play with this yet -- but my gut reaction is : starting with pi-olz88.c , break main into init, process, print (avoid giving compiler too much to deal with). declare register variable (either a or b). Note that globals are NOT in registers, and this
is a problem with the piz88.c source. When I get a chance, I will dive into this. I should be retired, but am not...
Also, do NOT assume that "optimize" will be very effective -- just plain peephole. Those changes should get the "native"
compilers to VERY competitive with z88

Just some food for thought.

FredW

(and, PS. I got to this thread from my "ALTAIR C is slow" comment. I, strangely, don't want to speed it up! Having it
"nice and slow" makes me think more slowly and deeply. -Or- I am just an old fossil...).

Frank P.

unread,
May 19, 2021, 4:56:09 PM5/19/21
to Altair-Duino
Fred, the piz88.c code was ultimately derived from a FOCAL program in which, like BASIC, everything is essentially global; whereas pi-olz88.c code came from de-obfuscation and generalization of a real C program. There is a key variable in both programs, as I recall, that needs to be a 32-bit integer, and therein lies a lot of the slowdown. What 16-bit integer you could reasonably declare "register" in that program and achieve any improvement is not obvious. I don't think Aztec C, BDC C, or Z88DK (targeted to the 8080) would make use of "register" anyway. Haven't seriously looked at the others. But at least Z88DK was useful for the TI-83 .
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages